Publish Nuget packages in Azure DevOps Pipelines

In Azure DevOps, Pipelines can be used to build your solution, create a Nuget package and publish the Nuget package to the Nuget feed for further usage. This post shows how you can implement this and use the new Nuget package in Visual Studio.

Setup Azure DevOps project and git Repository

Open the required Azure DevOps project, or create a new Azure DevOps project. Add a Pipeline build. This demo will create a Nuget package from a .NET Standard library using .NET Core. The yml file is created and added to the git source code.

The dotnet core pipeline is used.

https://docs.microsoft.com/en-us/azure/devops/pipelines/ecosystems/dotnet-core

Create a Nuget Feed

A Nuget feed can be created in the Artifacts.

Open the feed settings and add the permission for the build agent identity. The build agent requires this permission to deploy the Nuget package to the feed.

Pack the .NET Core library

Create a new pack task in the yml pipeline file. This task does a dotnet pack for all csproj files.

- task: DotNetCoreCLI@2
  displayName: "Pack"
  inputs:
    command: 'pack'
    packagesToPack: '**/*.csproj'
    versioningScheme: 'off'

Azure Devops Pipelines also provides a UI to help you create the yml code.

Push the Nuget package to the Nuget Feed

Create a Pipeline task to publish the nupkg files. The task uses nupkg files created in the pack task, and pushes them to the feed.

- task: DotNetCoreCLI@2
  displayName: "Publish"
  inputs:
    command: 'push'
    packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg'
    nuGetFeedType: 'internal'
    publishVstsFeed: 'd09fc...'

Azure Devops provides a UI for implementing the yml code. The publishVstsFeed property is set using the target.

When you run a build, the Nuget packages should be deployed to the feed.

Add the Nuget feed to Visual Studio

In Visual Studio you need to add a new package source to the Nuget feeds. You can get the Nuget feed from the build logs. The source feed ends with index.json.

When you open the Nuget Manager for your project, the new feed can be selected on the right hand side drop down, and the published packages can be used.

Links:

https://dev.azure.com/

https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/package/nuget?view=azure-devops

https://docs.microsoft.com/en-us/azure/devops/pipelines/ecosystems/dotnet-core?view=azure-devops

https://docs.microsoft.com/en-us/azure/devops/pipelines/?view=azure-devops

One comment

  1. […] Publish Nuget packages in Azure DevOps Pipelines […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: