Publish NuGet packages to NuGet.org with Azure Pipelines
Using Azure Pipelines, developers can streamline the process of publishing their NuGet packages to feeds and public registries. In this tutorial, we'll explore how to leverage YAML and classic pipelines to publish NuGet packages to NuGet.org. In this article, you'll learn how to:
- Authenticate with NuGet.org.
- Create service connections.
- Publish packages to NuGet.Org.
Prerequisites
An Azure DevOps organization and a project. Create one for free, if you don't have one already.
- The Administrator role for service connections in your Azure DevOps project.
A nuget.org account.
Create an API key
Navigate to NuGet.org and sign in to your account.
Select your user name icon, and then select API Keys.
Select Create, and then provide a name for your key. Assign the Push new packages and package version scope to your key, and enter
*
in the Glob Pattern field to include all packages.Select Create when you're done.
Select Copy and save your API key in a safe location.
Create a service connection
Sign in to your Azure DevOps organization
https://dev.azure.com/<Your_Organization>
and then navigate to your project.Select Project settings located at the bottom left corner of the page.
Select NuGet, and then select Next.
Select ApiKey as your authentication method and set the Feed URL to the following:
https://api.nuget.org/v3/index.json
.Enter the ApiKey you generated earlier in the ApiKey field, and then provide a name for your service connection.
Check the Grant access permission to all pipelines checkbox, and then select Save when you're done. To select this option, you'll need the service connection Administrator role.
Publish packages
Sign in to your Azure DevOps organization
https://dev.azure.com/<Your_Organization>
and then navigate to your project.Select Pipelines, and then select your pipeline. Select Edit to edit your pipeline.
Select + to add a new task, and then search for the .NET Core task. select Add to add it to your pipeline.
Select the pack command from the command's dropdown menu, and then select the Path to csproj or nuspec file(s) to pack. You can keep the default values for the other fields depending on your scenario.
Select + to add a new task, and then search for the NuGet task. select Add to add it to your pipeline.
Select the push command from the command's dropdown menu, and then select the Path to NuGet package(s) to publish.
Select External NuGet server for your Target feed location. Then, in the NuGet server field, select the service connection you created earlier.
Once completed, you can visit the packages page on nuget.org, where you can find your recently published package listed at the top.