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

Azure DevOps Services | Azure DevOps Server 2022 - Azure DevOps Server 2019 | TFS 2018

With Azure Artifacts, you can publish your NuGet packages to public or private feeds and share them with others based on your feed's visibility settings. This article will guide you through connecting to Azure Artifacts and publishing your NuGet packages.

Prerequisites

Connect to feed

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

  2. Select Connect to feed.

    A screenshot showing how to connect to a feed.

  3. Select NuGet.exe.

    A screenshot the feed's connection type.

  4. Follow the instructions in Project setup to set up your nuget.config file.

    Project setup

  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.

    Connect to feed - TFS

  4. Select NuGet and follow the instruction to connect to your feed.

    Connect to NuGet feed - TFS

Publish packages

To publish a NuGet package to your feed, run the following command in an elevated command prompt. Replace the placeholders with the appropriate information:

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

Note

The ApiKey is only used as a placeholder.

  • Example:

    nuget push MyPackage.5.0.2.nupkg -src https://pkgs.dev.azure.com/MyOrg/MyProject/_packaging/MyFeed/nuget/v3/index.json -ApiKey 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.

    nuget sources Add -Name <PACKAGE_SOURCE> -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. Publish your package:

    nuget push <PACKAGE_PATH> -src <PACKAGE_SOURCE> -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
    

Restore packages

To restore your packages, run the following command in an elevated command prompt:

nuget.exe restore