Publish a NuGet package from the command line

Azure DevOps Services | Team Foundation Server 2018 | Team Foundation Server 2017

Publish NuGet packages to a feed in Azure Artifacts to share them with your team and your organization.

First, get the tools and your feed URL:

  1. Go to your feed (or create a feed if you haven't).

  2. Select Connect to feed:

    Connect to feed button on the upper right of the page

  3. Select NuGet.exe under the NuGet header.

  4. If you installed NuGet, and you have at least one edition of Visual Studio on your machine, you can move to the next step. Otherwise:

    1. Select Get the tools in the upper-right corner.
    2. Download the latest NuGet version if you haven't yet.
    3. Download and install the credential provider (if you don't have any Visual Studio edition).
  5. Copy the xml code snippet in the Project setup section and add/create a nuget.config file for your project. Place your file in the same folder as your .csproj or .sln file.

  6. To publish your package to your feed, run the command in the Publish packages section in an elevated PowerShell window. Don't forget to specify your local package path (for example: ..\HelloWorld\NuGetPackage\HelloWorld1.0.0.nupkg).

    NuGet publish instructions in Connect to feed dialog box

Note

Publish a NuGet package by using the NuGet CLI

To publish your package by using the NuGet CLI, you need the following variables:

  • SourceName: The name of your feed created in step 1 of this article.
  • SourceURL: The feed URL (step 6). You can find it in the Project setup section, under value. In the Azure DevOps portal, go to Artifact > Your feed name > Connect to feed > Project setup.
  • UserName and PAT: Your username and personal access token. For help with setting up your credentials, see Authenticate access with personal access tokens.
  1. Go to your feed (or create a feed if you haven't).

  2. Select Connect to feed:

    Connect to feed button on the upper right of the page

  3. Follow steps 1 and 2 to get the tools, add the feed to your local NuGet configuration, and push the package.

    NuGet publish instructions in the Connect to feed dialog box

Note

You can use the symbols of your NuGet packages to debug your application. You can publish your symbols to a file share using the index sources and publish symbols task as well as in your build pipeline that produces the NuGet packages. See Symbol files overview and How to publish your symbols for debugging for more information. Publishing your symbols to Azure Artifact feeds from the command line is not currently supported.

Install and publish a sample NuGet package

If you don't have a package but want to try publishing, you can install a NuGet sample package from the public NuGet gallery.

  1. Install the sample NuGet package:

    nuget install HelloWorld -ExcludeVersion
    
  2. Publish the sample NuGet package to your feed.

    Run these two commands in an elevated command prompt to add the source to your nuget.config file and push your package to your feed. Replace the placeholders with the respective values.

    nuget sources add -Name <SourceName> -Source <SourceURL> -username <UserName> -password <Pat>
    nuget push -Source <SourceName> -ApiKey az <PackagePath exp:(.\Get-Hello.1.0.0.nupkg)>
    

Create and publish your own NuGet package

  1. Create your own NuGet package by following the steps in Create NuGet packages.

  2. Publish your package to your feed.

    Run these two commands in an elevated command prompt to add the source to your nuget.config file and push your package to your feed. Replace the placeholders with the respective values.

    nuget sources add -Name <SourceName> -Source <SourceURL> -username <UserName> -password <Pat>
    nuget push -Source <SourceName> -ApiKey az <PackagePath exp:(.\Get-Hello.1.0.0.nupkg)>
    

Work with upstream sources

Upstream sources enable you to use a single feed to store and consume packages from both public (NuGet.org, npmjs.com, Maven Central, and PyPI) and authenticated feeds (Azure Artifacts feeds).

See Understanding upstream sources to get familiar with the concepts. You can also check out the following articles to learn how to: