Edit

Publish NuGet packages from the command line (NuGet.exe)

Azure DevOps Services | Azure DevOps Server | Azure DevOps Server 2022

This article guides you through setting up your project and publishing your NuGet packages using the NuGet command-line interface.

Prerequisites

Product Requirements
Azure DevOps - An Azure DevOps organization.
- An Azure DevOps project.
- An Azure Artifacts feed.
- Download and install nuget.exe version 4.8.0.5385 or later. We recommend NuGet 5.5.x or later, which includes important bug fixes for cancellations and timeouts.

Set up the Azure Artifacts Credential Provider

The Azure Artifacts Credential Provider enables secure authentication to your Azure Artifacts feeds. To use it with nuget.exe, you must first add it to NuGet’s plugin search path. For details, see Plugin Installation and discovery. Once the plugin is added, follow the installation steps for your operating system:

Use one of the following methods to install the Azure Artifacts Credential Provider:

Manual installation

  1. Download the latest Microsoft.NetFx48.NuGet.CredentialProvider.zip release.

  2. Extract the zip file.

  3. Copy the netfx folder from the extracted archive to %UserProfile%/.nuget/plugins/. The netfx folder is required for nuget.exe compatibility.

Install using the helper script

Alternatively, you can use the automated helper script for a streamlined installation. Ensure you have PowerShell 5.1 or later, and then run:

iex "& { $(irm https://aka.ms/install-artifacts-credprovider.ps1) } -AddNetfx"

For more information, see the Azure Artifacts Credential Provider repository.

Connect to a feed

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

  2. Select Artifacts, and then select your feed from the dropdown menu.

  3. Select Connect to feed, and then select NuGet.exe from the left navigation pane.

  4. Add a nuget.config file to your project, in the same folder as your .csproj or .sln file. Paste the provided XML snippet into your file. The snippet should look like the following:

    • Organization-scoped feed:

      <?xml version="1.0" encoding="utf-8"?>
      <configuration>
        <packageSources>
          <clear />
          <add key="<SOURCE_NAME>" value="https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/_packaging/<FEED_NAME>/nuget/v3/index.json" />
        </packageSources>
      </configuration>
      
    • Project-scoped feed:

      <?xml version="1.0" encoding="utf-8"?>
      <configuration>
        <packageSources>
          <clear />
          <add key="<SOURCE_NAME>" value="https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/nuget/v3/index.json" />
        </packageSources>
      </configuration>
      
  1. Sign in to your Azure DevOps server, and then navigate to your project.

  2. Select Artifacts, and then select your feed.

  3. Select Connect to Feed, and then select NuGet.exe from the left navigation pane.

  4. Follow the instructions in the Project setup section to connect to your feed.

Publish packages to a feed in the same organization

Note

To publish packages to a feed, you must be a Feed Publisher (Contributor) or higher. See Manage permissions for more details.

Run the following command to publish a package to your feed. Replace the placeholders with the appropriate values:

nuget push <PACKAGE_PATH> -src https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/nuget/v3/index.json -ApiKey <ANY_STRING>

Example:

nuget push MyPackage.5.0.2.nupkg -src https://pkgs.dev.azure.com/MyOrg/MyProject/_packaging/MyFeed/nuget/v3/index.json -ApiKey AZ

Note

The api-key is required, but you can provide any string as its value when publishing to an Azure Artifacts feed.

Publish packages to a feed in another organization

To publish your NuGet packages to a feed in a different Azure DevOps organization, you must first create a personal access token (PAT) in the target organization.

  1. Navigate to the organization hosting the target feed and create a personal access token (PAT) with Packaging > Read & write scope.

  2. Run the following command to add your package source to your nuget.config file. This will add your PAT to your nuget.config file. Store this file in a safe location, and make sure that you don't check it into source control.

    nuget sources Add -Name <SOURCE_NAME> -Source https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/nuget/v3/index.json -UserName <USER_NAME> -Password <PERSONAL_ACCESS_TOKEN> -config <PATH_TO_NUGET_CONFIG_FILE>
    
  3. Run the following command to publish your package:

    nuget push <PACKAGE_PATH> -src <SOURCE_NAME> -ApiKey <ANY_STRING>
    

Example:

nuget sources Add -Name "MySource" -Source https://pkgs.dev.azure.com/MyOrg/MyProject/_packaging/MyFeed/nuget/v3/index.json -UserName MyUserName -Password YourPersonalAccessToken -config ./nuget.config
nuget push nupkgs/mypackage.1.1.8.nupkg -src MySource -ApiKey AZ

Note

If your organization is using a firewall or a proxy server, make sure you allow Azure Artifacts Domain URLs and IP addresses.