Get started with NuGet packages
Azure DevOps Services | TFS 2018 | TFS 2017
Before you start
For this quickstart, you must have NuGet installed and set up. To learn more about NuGet installation and set up, see the official documentation.
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.
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 Marketplace page for Azure Artifacts.
Create a feed
Already have a feed? Skip to the next step.
There are two types of feeds: project scoped and organization scoped feeds. All public feeds are project-scoped and they inherit the visibility settings of the hosting project.
Go to Azure Artifacts.
Select Create Feed.
Give your feed a Name and choose its visibility, upstream sources and scope.
Select Create.
Note
Enabling upstream sources allow you to use your favorite OSS packages and gives you more protection against outages and corrupted or compromised 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
Go to Build & Release and select Packages.
Select + New feed.
Give your feed a Name, a Description, and set up who can read, who can contribute and if you want to Include external packages.
Note
Enabling upstream sources allow you to use your favorite OSS packages and gives you more protection against outages and corrupted or compromised packages.
See Feeds and views permissions to learn more about managing feed permissions.
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:
Go to your feed (or create a feed if you haven't).
Select Connect to feed:
Select NuGet.exe under the NuGet header.
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:
- Select Get the tools in the upper-right corner.
- Download the latest NuGet version if you haven't yet.
- Download and install the credential provider (if you don't have any Visual Studio edition).
Copy the
xml
code snippet in the Project setup section and add/create anuget.config
file for your project. Place your file in the same folder as your .csproj
or.sln
file.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).
Note
- The NuGet
push
command requires an API key. You can use any non-empty string for this variable. In our example, we used the stringkey
. - For more information on using credential providers with NuGet, see Creating a NuGet credential provider.
- For more information on using personal access tokens, see Authenticate access with personal access tokens.
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.
Go to your feed (or create a feed if you haven't).
Select Connect to feed:
Follow steps 1 and 2 to get the tools, add the feed to your local NuGet configuration, and push the package.
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.
Install the sample NuGet package:
nuget install HelloWorld -ExcludeVersion
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
Create your own NuGet package by following the steps in Create NuGet packages.
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)>
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 information
Go to your feed (or create a feed if you haven't).
Select Connect to feed:
Select the Visual Studio tab under the NuGet header
Follow the instructions under Machine setup
Go to your feed (or create a feed if you haven't).
Select Connect to feed:
Copy the NuGet package source URL:
Windows: Add the feed to your NuGet configuration
- On the Tools menu, select Options.
- Expand NuGet Package Manager and select Package Sources.
- Select the green plus in the upper-right corner.
- At the bottom of the dialog box, enter the feed's name and the URL that you got in the last step.
- Select Update.
- If you enabled the nuget.org upstream source, clear the check box for the nuget.org package source.
- Select OK.
- Go to the steps for consuming packages.
macOS: Add the feed to your NuGet configuration
Get a personal access token (PAT) and make a note of it.
Open the Preferences dialog box from the Visual Studio menu on the menu bar.
Select NuGet > Sources.
Select Add. Then enter your feed's name, the URL, any username, and your PAT as the password.
Select OK.
If you enabled the nuget.org upstream source, clear the check box for the nuget.org package source.
Select OK again.
Consume packages
You can now discover and use packages in this feed. To add a package reference to a project:
- Find your project in Solution Explorer.
- Right-click References.
- Select Manage NuGet Packages.
- In the Package source drop-down list, select your feed.
- Look for your package in the list.
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:
- On the upstream source (for example, nuget.org), copy the
Install-Package
command. - In Visual Studio, open the Package Manager Console from Tools > NuGet Package Manager.
- 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.