Automate Package Publication with Git and YAML

Automate Package Publication with Git and YAML





Let’s simplify publishing new NuGet packages for x++ builds

You can quite easily automate the publishing of NuGet packages with an extra repo and a pipeline to do the work for you.

First, you’ll need an Azure DevOps project preferably using Git. Next, create ann artifact feed. Go to Artifact on the left hand side in DevOps. If you don’t see it, you may not have permissions or the appropriate license. 

Next, create a feed and give it a name. In this instance, I’m going to name it D365FONuGets

Next, create a new git repo called “nugets”

Next, map it in Visual Studio by going to the Git Menu then “Clone Repository”. From DevOps, you can get the clone link from the repo home page.

Next, clone in Visual Studio:

Confirm you have the repo selected in Visual Studio and now you can place the nugets, nuget.config, and packages.config in the folder you mapped, like so:

You can get your nuget.config file from Azure DevOps by selecting your Feed in the upper left then clicking on “connect to feed”. From there, you will get a sample, like this:

nuget.config Sample:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="D365FONuGets" value="https://pkgs.dev.azure.com/BusinessCompany/Explore/_packaging/D365FONuGets/nuget/v3/index.json" />
  </packageSources>
</configuration>

Next, you’ll have to make your packages.config file with the files and versions available from the LCS asset library; a sample is below.

packages.config sample:

<?xml version=”1.0″ encoding=”utf-8″?>
<packages>
  <package id=”Microsoft.Dynamics.AX.Platform.DevALM.BuildXpp”         version=”7.0.7690.33″    targetFramework=”net40″ />
  <package id=”Microsoft.Dynamics.AX.Application1.DevALM.BuildXpp”     version=”10.0.2345.118″  targetFramework=”net40″ />
  <package id=”Microsoft.Dynamics.AX.Application2.DevALM.BuildXpp”     version=”10.0.2345.118″  targetFramework=”net40″ />
  <package id=”Microsoft.Dynamics.AX.ApplicationSuite.DevALM.BuildXpp” version=”10.0.2345.118″  targetFramework=”net40″ />
  <package id=”Microsoft.Dynamics.AX.Platform.CompilerPackage”         version=”7.0.7690.33″    targetFramework=”net40″ />
</packages>

Next, we’ll need to create a pipeline that will on commit take the latest NuGet packages and publish them to your feed. This simply automates a step you could do manually if you’d like. A sample pipeline is below and it will require some modification to work for your scenario:

# Runs when changes are pushed to ‘main’ that include any .nupkg files
trigger:
  branches:
    include:
      – main
  paths:
    include:
      – ‘**/*.nupkg’

# Use a Microsoft-hosted Windows agent
pool:
  vmImage: ‘windows-latest’   # or ‘windows-2022’ if you want to pin the image

variables:
  # Azure Artifacts feed name (Project/Feed or just Feed if project-scoped)
  # In my instance, my project name is “Explore” and my Azure DevOps Artifact Feed name is “D365FONuGets”
  azureArtifactsFeed: ‘Explore/D365FONuGets’

stages:
– stage: PublishNuGets
  displayName: ‘Publish NuGet packages to Azure Artifacts’
  jobs:
  – job: PushNuGets
    displayName: ‘Push .nupkg files from repo’
    steps:
      # Checkout the current repo so we can see the .nupkg files
      – checkout: self
        clean: true

      # Get credentials for Azure Artifacts feeds (injects auth into NuGet)
      – task: NuGetAuthenticate@1
        displayName: ‘Authenticate to Azure Artifacts’

      # Push all .nupkg files in the repo to the configured Azure Artifacts feed
      – task: NuGetCommand@2
        displayName: ‘Push NuGet packages to feed’
        inputs:
          command: ‘push’
          publishVstsFeed: ‘$(azureArtifactsFeed)’
          # Find all NuGet packages in the repo tree
          packagesToPush: ‘$(Build.SourcesDirectory)/**/*.nupkg’
          # Don’t fail if package version already exists in the feed
          allowPackageConflicts: true
          verbosity: ‘Detailed’
 

Commit that and sync.

Next, let’s create the pipeline from the YAML. In DevOps go to pipelines on the left then click on “New Pipeline”, select “Azure Repos Git”, select the nugets repo you created, select “existing Azure Pipelines YAML file, then select “/publish-nugets.yml” and click continue.

Next, click the down arrow next to run and select “save”. Next, we’ll need to go to the feed, go to settings and confirm “Project Collection Build Service” or “(your instance) Build Service” have at least contributor access. Once confirmed, open the pipeline and tell it to run. Go to Pipelines > Pipelines > Nugets > “Run Pipeline”.

Once that runs successfully, you should see artifacts in your feed.

This will automate publishing your nuget packages from LCS but in order to perform a build, we’ll need access to those .config files. That’s a problem for another day but for now, you can use this approach to create the .config files and update the new packages then copy/paste the updated .config files where needed. All files for the nuget repo can be found at https://github.com/NathanClouseAX/GitALM/tree/main/nugets.

 

 

 

Original Post https://www.atomicax.com/blog-entry/automate-package-publication-git-and-yaml

0 Votes: 0 Upvotes, 0 Downvotes (0 Points)

Leave a reply

Follow
Search
Loading

Signing-in 3 seconds...

Signing-up 3 seconds...