Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Azure DevOps Services | Azure DevOps Server | Azure DevOps Server 2022 | Azure DevOps Server 2020
This guide walks you through configuring your project to publish NuGet packages using the dotnet command-line interface.
Prerequisites
| Product | Requirements |
|---|---|
| Azure DevOps | - An Azure DevOps organization. - An Azure DevOps project. - An Azure Artifacts feed. - Download and install the Azure Artifacts Credential Provider. - Download and install .NET Core SDK (2.1.400+). |
Create a feed
If you already have a feed, proceed to the next step. Otherwise, follow the instructions below to create a new one:
Sign in to your Azure DevOps, and navigate to your project.
Select Artifacts, and then select Create Feed.
Enter a descriptive Name for your feed and define its Visibility (who can use your feed). Specify the Scope of your feed, and if you wish to include packages from public sources, check the Include packages from common public sources checkbox.
Select Create when you're done.
Connect to a feed
Before you can publish packages to your feed, you must authenticate with Azure Artifacts. Follow the instructions below to set up your project and authenticate with your feed:
Sign in to your Azure DevOps organization, and then navigate to your project.
Select Artifacts, and then select your feed from the dropdown menu.
Select Connect to feed, and then select dotnet from the NuGet section on the left.
Create a nuget.config file in the same folder as your csproj or sln file. Copy the following XML snippet and paste it into your new file, replacing the placeholders with the relevant information:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="<FEED_NAME>" value="https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/nuget/v3/index.json" />
</packageSources>
</configuration>
Publish packages to a feed in the same organization
Run the following command to publish a package to your feed. Replace the placeholders with the appropriate values:
dotnet nuget push --source https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/nuget/v3/index.json --api-key <ANY_STRING> <PACKAGE_PATH>
Example:
dotnet nuget push --source https://pkgs.dev.azure.com/MyOrg/MyProject/_packaging/MyFeed/nuget/v3/index.json --api-key AZ bin/MyPackage.5.0.2.nupkg
Note
The api-key parameter is required when publishing to an Azure Artifacts feed, but you can use any string as its value.
Publish packages to a feed in a different 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, add the new package source to your configuration file, and then run the publish command:
Navigate to the organization hosting the target feed and create a personal access token (PAT) with Packaging > Read & write scope.
Replace the <PERSONAL_ACCESS_TOKEN> placeholder with your personal access token, and then run the following command to add your package source to your nuget.config file. Ensure that this file is stored securely and is not checked into source control.
dotnet nuget add source https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/nuget/v3/index.json --name <SOURCE_NAME> --username <USER_NAME> --password <PERSONAL_ACCESS_TOKEN> --configfile <PATH_TO_NUGET_CONFIG_FILE>Run the following command to publish your package:
dotnet nuget push --source <SOURCE_NAME> --api-key <ANY_STRING> <PACKAGE_PATH>
Example:
dotnet nuget add source https://pkgs.dev.azure.com/MyOrg/MyProject/_packaging/MyFeed/nuget/v3/index.json --name MySource --username MyUserName --password MyPersonalAccessToken --configfile ./nuget.config
dotnet nuget push --source MySource --api-key AZ nupkgs/mypackage.1.1.0.nupkg
Note
If your organization uses a firewall or proxy server, make sure that the Azure Artifacts Domain URLs and IP addresses are allowed.