Get started with NuGet packages in Azure DevOps Services and TFS

Azure DevOps Services | TFS 2018 | TFS 2017

Before you start

This guide assumes you've already set up Azure Artifacts. You can check out how to license the extension in the License Azure Artifacts guide.

Azure Artifacts is an extension that comes pre-installed on TFS 2017 or newer, if it was removed from your Azure DevOps organization, you can install it from the Marketplace page for Azure Artifacts.

Create a feed

Already have a feed? Skip to the next step.

A feed is a container for packages. You consume and publish packages through a particular feed.

  1. Navigate to Azure Artifacts:

  2. Select + New feed:

  3. In the dialog:

    • Give the feed a name.
    • Choose who can read and contribute (or update) packages in your feed.
    • Choose the upstream sources for your feed.
    • When you're done, choose Create.

      Most of the default settings work great for most feed users. Making your feed organization visible means it's easy to share a single source of packages across your entire team. Enabling upstream sources to public sources makes it easy to use your favorite OSS packages, and can also give you additional protection against outages and corrupted or compromised packages.

  1. Navigate to the Packages page:

    Go to Azure Artifacts

  2. Select + New feed:

    New feed button

  3. In the dialog:

    • Give the feed a name.
    • Choose who can read and contribute (or update) packages in your feed.
    • Choose the upstream sources for your feed.
    • When you're done, choose Create.

      Most of the default settings work great for most feed users. Making your feed organization visible means it's easy to share a single source of packages across your entire team. Enabling upstream sources to public sources makes it easy to use your favorite OSS packages, and can also give you additional protection against outages and corrupted or compromised packages.

      New feed dialog

You can change these settings later by editing the feed.

Publish a package

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. Navigate to your feed (or create a feed if you haven't).

  2. Select Connect to feed:

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

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

  2. Select Connect to feed:

    Connect to feed button in the upper-right of the page

  3. Follow steps 1, 2, and 3 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

You can also manually construct a push command as follows:

nuget.exe push -Source {NuGet package source URL} -ApiKey key {your_package}.nupkg`

Notes:

  • The NuGet client's push command requires an API key. You can use any non-empty string you want; in this example, we used key.
  • If you're prompted for credentials in the command line, ensure that the credential provider downloaded is in the same folder as NuGet.exe. For more help using credential providers with NuGet, see here.

Get a sample package to push

If you don't have a package but want to try this out, Microsoft provides a sample package on the public NuGet gallery.

  • Run these two commands:

    nuget.exe install Azure DevOps Services-HelloWorld -ExcludeVersion
    nuget.exe push -Source {NuGet package source URL} -ApiKey key Azure DevOps Services-HelloWorld\Azure DevOps Services-HelloWorld.nupkg
    

Consume your package in Visual Studio

To consume NuGet packages from a feed, add the feed's NuGet endpoint as a package source in Visual Studio.

Note

Azure Artifacts feeds work seamlessly with the NuGet Package Manager for Visual Studio 2015 extension as of Visual Studio 2015 Update 1. If you haven't installed Update 1 or later, you can update to the latest version of the NuGet Package Manager extension directly. Using Visual Studio for Mac? See this guidance.

Get your feed's NuGet package source URL

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

  2. Select Connect to feed:

  3. Copy the NuGet package source URL:

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

  2. Select Connect to feed:

    Connect to feed button in the upper-right of the page

  3. Copy the NuGet package source URL:

    NuGet Package source URL in the Connect to feed dialog

Windows: Add the feed to your NuGet configuration

  1. On the Tools menu, select Options....
  2. Expand NuGet Package Manager and select Package Sources.
  3. Click the green plus in the upper right corner.
  4. At the bottom of the dialog, enter the feed's name and the URL you got in the last step.
  5. Select Update.
  6. If you enabled the nuget.org upstream source, uncheck the nuget.org package source. Add new NuGet source
  7. Select OK.
  8. Click here to continue.

macOS: Add the feed to your NuGet configuration

  1. Get a Personal Access Token (PAT) and make a note of it.
  2. Open the Preferences dialog from the Visual Studio menu in the menu bar.
  3. Select NuGet -> Sources.
  4. Select Add then enter your feed's name, URL, any username, and your PAT as the password.
  5. Select OK.
  6. If you enabled the nuget.org upstream source, uncheck the nuget.org package source.
  7. Select OK again.

    Visual Studio for Mac preferences window with Azure DevOps Services feed added

Consume packages

You can now discover and use packages in this feed. To add a package reference to a project:

  1. Find your project in Solution Explorer.
  2. Right-click References.
  3. Select Manage NuGet Packages....
  4. In the Package source dropdown, select your feed.
  5. Look for your package in the list.

    Select feed source

If you're using upstream sources, package-versions in the upstream source that haven't yet been saved into your feed (by using them at least once) won't appear in the NuGet Package Manager search. To install these packages:

  1. On the upstream source (e.g. nuget.org), copy the Install-Package command.
  2. In Visual Studio, open the Package Manager Console from Tools > NuGet Package Manager.
  3. Paste the Install-Package command into the Package Manager Console and run it.

Use symbols to debug

Symbol servers enable debuggers to automatically retrieve the correct symbol files for packages without knowing product names, build numbers or package names. If symbols have been published for your packages, connect Visual Studio to the Symbol Server in Azure Artifacts to use symbols as you debug your packages.

Using Visual Studio 2013 or earlier

You'll need to get a Personal Access Token. When you're prompted for a username and password, use any username and your PAT as the password.

Automate the process with continuous integration

You can use continuous integration systems like Team Build to automate the packing and publishing of your packages. To get started with continuous integration, see the NuGet in Team Build guidance.

What's next?

For more advanced topics, check out the content summary.