Publish and restore NuGet packages from the command line (dotnet)
TFS 2018
With Azure Artifacts, you can publish and restore your NuGet packages to/from your feed and share them with others based on your feed's visibility settings. This article will guide you through setting up your project to publish and restore your packages using the dotnet command-line interface.
Prerequisites
An Azure DevOps organization. Create an organization, if you don't have one already.
An Azure Artifacts feed. Create a new feed if you don't have one already.
Download and install .NET SDK.
Connect to feed
Select Build and Release > Packages.
Select your feed from the dropdown menu or create one if you haven't.
Select Connect to feed.
Select NuGet and follow the instruction to connect to your feed.
Publish packages
To publish a package to your feed, run the following command in an elevated command prompt. Replace the placeholders with the appropriate information:
dotnet nuget push <PACKAGE_PATH> --source https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/nuget/v3/index.json --api-key <ANY_STRING>
Note
The api-key
is only used as a placeholder.
Example:
dotnet nuget push MyPackage.5.0.2.nupkg --source https://pkgs.dev.azure.com/MyOrg/MyProject/_packaging/MyFeed/nuget/v3/index.json --api-key AZ
Publish packages from external sources
Create a personal access token (PAT) with packaging read and write scope.
Add your package source to your nuget.config file. This will add your PAT to your nuget.config file. Make sure to store this file in a safe place, and do not check this file 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>
Publish your package:
dotnet nuget push <PACKAGE_PATH> --source <SOURCE_NAME> --api-key <ANY_STRING>
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 nupkgs/mypackage.1.1.0.nupkg --source MySource --api-key AZ
Note
If your organization is using a firewall or a proxy server, make sure you allow Azure Artifacts Domain URLs and IP addresses.
Restore packages
To restore your packages, run the following command in an elevated command prompt. The --interactive
flag is used to prompt the user for credentials.
dotnet restore --interactive