title | description | ms.custom | ms.topic | ms.date | monikerRange | recommendations |
---|---|---|---|---|---|---|
Publish NuGet packages to NuGet.org (Classic/YAML) |
Learn how to publish NuGet packages to NuGet.org using Azure Pipelines. |
peer-review-program |
conceptual |
12/23/2024 |
<= azure-devops |
true |
Using Azure Pipelines, developers can streamline the process of publishing their NuGet packages to feeds and public registries. This article will walk you through publishing your NuGet packages to NuGet.org.
Product | Requirements |
---|---|
Azure DevOps | - An Azure DevOps project. - Permissions: - To grant access to all pipelines in the project, you must be a member of the Project Administrators group. - To create service connections, you must have the Administrator or Creator role for service connections. |
NuGet.org | - A NuGet account. |
-
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 secure location.
-
Sign in to your Azure DevOps organization, and then navigate to your project.
-
Select
Project settings in 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:
https://api.nuget.org/v3/index.json
. -
Enter the ApiKey you created earlier in the ApiKey field, and provide a name for your service connection.
-
Select the Grant access permission to all pipelines checkbox, and then select Save when you're done.
Note
If you're using Ubuntu 24.04 or higher, you must use the NuGetAuthenticate
task with the .NET CLI instead of the NuGetCommand@2
task. See Support for newer Ubuntu hosted images for more details.
-
Sign in to your Azure DevOps organization, and then navigate to your project.
-
Select Pipelines, select your pipeline definition, and then select Edit.
-
Add the following snippet to your YAML pipeline. Replace the placeholder with the name of the service connection you created earlier:
steps: - task: DotNetCoreCLI@2 displayName: 'dotnet pack' inputs: command: pack - task: NuGetCommand@2 displayName: 'NuGet push' inputs: command: push nuGetFeedType: external publishFeedCredentials: <NAME_OF_YOUR_SERVICE_CONNECTION>
-
Sign in to your Azure DevOps organization, and then navigate to your project.
-
Select Pipelines, select your pipeline definition, and then select Edit.
-
Select + to add a new task, and then add the .NET Core task to your pipeline.
-
From the command dropdown, select pack, and then select the Path to csproj or nuspec file(s) to pack. You can leave the default values for the other fields.
-
Select + to add another task, then add the NuGet task to your pipeline.
-
From the command dropdown, select push, and then select the Path to NuGet package(s) to publish.
-
Select External NuGet server for the Target feed location, and then select the service connection you created earlier from NuGet server dropdown menu.
:::image type="content" source="media/nuget-push-task.png" alt-text="A screenshot displaying how to configure a NuGet push task to an external NuGet server.":::
Once the pipeline completes successfully, navigate to the packages page on NuGet.org, where you will find your recently published package listed at the top.
:::image type="content" source="media/published-package.png" alt-text="A screenshot showing the published packages on NuGet.org.":::