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://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
[…] Publish Nuget packages in Azure DevOps Pipelines […]