azure-devopsazure-pipelinesnuget

AzureDevOps: NuGetCommand@2 push to DotNetCoreCLI@2 custom nuget push, with VSTS feed?


In a pipeline under Ubuntu 24.04, the old NuGetCommand@2 task doesn't work anyore, because requires .NET Mono, which is no longer part of Ubuntu 24.04 build machines.

So I end up with something like this task:

  - task: DotNetCoreCLI@2
    displayName: DotNet NuGet push
    inputs:
      # required, because NuGetCommand@2 allowPackageConflicts missing.
      command: 'custom'
      custom: 'nuget'
      # --skip-duplicate is the direct option 
      # to replace allowPackageConflicts: true. 
      arguments: 'push $(Build.SourcesDirectory)/packagesMyPacksDir/*.nupkg --source https://pkgs.dev.azure.com/my-company/<guid1>/_packaging/<guid2>/nuget/v3/index.json -ApiKey VSTS'

But with a custom command, all the options to resolve the feed URL, as internally happening in the old NuGetCommand@2 task or with DotNetCoreCLI push, do not work.

My idea was to simply insert <guid1> and <guid2> into the --source URL, but when I looked at older builds, with the NuGetCommand@2 task, I noticed that the second GUID wasn't the /<guid2> value from previous publishVstsFeed:<guid1>/<guid2>, but another GUID with every new pipeline run.

So how do I build the --source URL?

Possible alternative: If there was a chance to list all NuGet packages to push, and use DotNetCoreCLI push commands in a loop, it might work without building a source URL, but I found no way yet to loop over a varying number of files.


Solution

  • Ran into the exact same problems converting our existing pipeline to keep working on the Ubuntu 24 image from DevOps. Eventually ended up with the following solution:

    - task: DotNetCoreCLI@2
      displayName: Custom push
      inputs:
        command: custom
        custom: nuget
        arguments: push $(Pipeline.Workspace)/{artifactName}/*.nupkg --source https://pkgs.dev.azure.com/${{ parameters.nugetFeedOrganization }}/${{ parameters.nugetFeedProject }}/_packaging/${{ parameters.nuGetFeed }}/nuget/v3/index.json --api-key VSTS --skip-duplicate
    

    Not ideal that we have to pass the organization/project as parameters (or hardcode them), since with the built in argument for feed just the feed name is enough to resolve it, but it works for us.