Muokkaa

Jaa


Publish NuGet packages to NuGet.org (Classic/YAML)

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.

Prerequisites

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.

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 secure location.

Create a service connection

  1. Sign in to your Azure DevOps organization, and then navigate to your project.

  2. Select gear icon Project settings in 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: https://api.nuget.org/v3/index.json.

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

  6. Select the Grant access permission to all pipelines checkbox, and then select Save when you're done.

Publish packages

  1. Sign in to your Azure DevOps organization, and then navigate to your project.

  2. Select Pipelines, select your pipeline definition, and then select Edit.

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

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.

A screenshot showing the published packages on NuGet.org.