Get started with NuGet packages

Azure DevOps Services | Azure DevOps Server 2020 | Azure DevOps Server 2019 | TFS 2018 - TFS 2017

Developers can use Azure Artifacts to publish and consume NuGet packages both to and from feeds and public registries. A feed is an organizational construct that hosts packages. You can create public and private feeds, and you can control who can access your packages by modifying feed permissions.

Prerequisites

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

Note

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

Create a feed

With Azure Artifacts, you can create two types of feeds: project-scoped and organization-scoped feeds. All public feeds are project-scoped and they inherit the hosting project's visibility settings. By default, any feed that's created by using the web UI is a project-scoped feed, as follows.

  1. From within your project, navigate to Azure Artifacts.

    Go to Azure Artifacts

  2. Select Create Feed.

    New feed button

  3. Give your feed a Name and choose its visibility, upstream sources, and scope settings.

    New feed dialog box

  4. When you are done, select Create.

Note

Enabling upstream sources allows you to consume packages from public registries and gives you more protection against outages and corrupted packages.

Azure Artifacts is installed by default for TFS 2017 customers. You must upgrade to TFS 2017 in order to use Azure Artifacts. If this is the first time using your feed, you might be asked to assign a license

  1. Go to Build & Release and select Packages.

    Go to Azure Artifacts TFS

  2. Select + New feed.

    New feed button TFS

  3. Give your feed a Name, a Description, and set up who can read, who can contribute and if you want to Include external packages.

    New feed dialog box TFS

Note

Enabling upstream sources allows you to consume packages from public registries and gives you more protection against outages and corrupted packages.

Connect to feed and publish packages

With Azure Artifacts, you can publish your NuGet packages to public or private feeds, and then share them with others, depending on your feed's visibility settings.

Here's how to connect to your feed and publish a package.

  1. Navigate 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.

    NuGet.exe feed connection

  4. If you have NuGet and Visual Studio installed, you can move to the next step. Otherwise:

    1. Select Get the tools button.
    2. Download the latest NuGet version.
    3. Download and install the credential provider.
  5. Create a nuget.config file with the following content and add it to your project in the same path as your .csproj or .sln file

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <packageSources>
        <clear />
        <add key="<orgName>" value="https://pkgs.dev.azure.com/<orgName>/_packaging/<orgName>/nuget/v3/index.json" />
      </packageSources>
    </configuration>
    
  6. Run the following command to publish your NuGet package to your feed.

    nuget.exe push -Source <orgName> -ApiKey az <packagePath>
    

Publish packages by using the command line

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

  • SourceName: the name of your feed.
  • SourceURL: the feed's source URL:
    https://pkgs.dev.azure.com/<orgName>/_packaging/<orgName>/nuget/v3/index.json
    
  • 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 one 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

Aside from publishing NuGet packages, Azure Artifacts also allow you to publish your symbols to file shares and symbols server. Publishing your symbols from the command line is not currently supported.

Install and publish a sample NuGet package

If you don't have a NuGet package but want to practice the steps to publish our packages to your feed, you can install the HelloWorld sample package.

  1. Install the sample NuGet package:

    nuget install HelloWorld -ExcludeVersion
    
  2. Set up your nuget.config file and publish your package to your feed

    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)>
    

Consume packages in Visual Studio

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

1. Get the feed's source URL

  1. Go to your feed or create one if you haven't.

  2. Select Connect to feed

    Connect to feed

  3. Select the Visual Studio tab under the NuGet section

  4. Copy the Source URL

    Copy source URL

  1. Go to your feed or create one if you haven't.

  2. Select Connect to feed

    Connect to feed

  3. Copy the Source URL:

    Copy source URL

2. Set up Visual Studio

Set up package source

  1. In Visual Studio, select Tools, and then Options.

  2. Expand the NuGet Package Manager section, and then select Package Sources.

  3. Enter the feed's Name and the Source URL, and then select the green (+) sign to add a source.

  4. If you enabled upstream sources in your feed, clear the nuget.org check box.

  5. Select OK.

    Set up visual studio: Windows

3. Consume packages

You can now find and consume packages from your feed by using Visual Studio.

  1. In Visual Studio, right-click on your project in the Solution Explorer, and then select Manage NuGet Packages.
  2. Select Browse, and then select your feed from the Package source drop-down list Select feed source
  3. Use the search bar to look for packages from your feed.

Note

If you're using upstream sources, any packages from upstream sources that haven't been saved to your feed yet (by using them at least once) won't appear in the Package Manager search result. To install those packages:

Consume package from NuGet.org

  1. Copy the Install-Package command from the public registry (NuGet.org).
  2. Select Tools then NuGet Package Manager to open the NuGet package manager.
  3. Paste the command into the Package Manager Console and select run.