Partager via


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

Connect to feed

  1. Select Build and Release > Packages.

  2. Select your feed from the dropdown menu or create one if you haven't.

  3. Select Connect to feed.

    A screenshot showing how to connect to a feed in TFS.

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

  1. Create a personal access token (PAT) with packaging read and write scope.

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