ערוך

שתף באמצעות


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

Create an API key

  1. Navigate to NuGet.org and sign in to your account.

  2. Select your user name icon, and then select API Keys.

  3. 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.

  4. Select Create when you're done.

  5. Select Copy and save your API key in a safe location.

Create a service connection

  1. Sign in to your Azure DevOps organization https://dev.azure.com/<Your_Organization> and then navigate to your project.

  2. Select gear icon Project settings located at the bottom left corner of the page.

  3. Select NuGet, and then select Next.

  4. Select ApiKey as your authentication method and set the Feed URL to the following: https://api.nuget.org/v3/index.json.

  5. Enter the ApiKey you generated earlier in the ApiKey field, and then provide a name for your service connection.

  6. 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

  1. Sign in to your Azure DevOps organization https://dev.azure.com/<Your_Organization> and then navigate to your project.

  2. Select Pipelines, and then select your pipeline. Select Edit to edit your pipeline.

  1. Select + to add a new task, and then search for the .NET Core task. select Add to add it to your pipeline.

  2. 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.

    A screenshot showing how to configure the dotnet pack task in a classic pipeline.

  3. Select + to add a new task, and then search for the NuGet task. select Add to add it to your pipeline.

  4. Select the push command from the command's dropdown menu, and then select the Path to NuGet package(s) to publish.

  5. Select External NuGet server for your Target feed location. Then, in the NuGet server field, select the service connection you created earlier.

    A screenshot showing how to configure a NuGet push task to an external NuGet server.

Once completed, you can visit the packages page on nuget.org, where you can find your recently published package listed at the top.

A screenshot showing the published packages in nuget.org.