Get started with NuGet packages
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.
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.
Select Create when you are done.
Connect to feed
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 set up your project.
Select Build and Release > Packages.
Select your feed from the dropdown menu or create one if you haven't.
Select Connect to feed.
Select NuGet and follow the instruction to connect to your feed.
Install and publish a sample NuGet package
If you don't have a NuGet package but want to practice the steps to publish NuGet packages to your feed, you can install the HelloWorld sample package.
Install the sample NuGet package:
nuget install HelloWorld -ExcludeVersion
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 key <PackagePath> #example:(.\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
Select Build and Release, and then select Packages.
Select your feed from the dropdown menu.
Select Connect to feed.
Copy your feed's Source URL.
2. Set up Visual Studio
Set up package source
In Visual Studio, select Tools, and then Options.
Expand the NuGet Package Manager section, and then select Package Sources.
Enter the feed's Name and the Source URL, and then select the green (+) sign to add a source.
If you enabled upstream sources in your feed, clear the nuget.org check box.
Select OK.
3. Consume packages
You can now find and consume packages from your feed by using Visual Studio.
- In Visual Studio, right-click on your project in the Solution Explorer, and then select Manage NuGet Packages.
- Select Browse, and then select your feed from the Package source drop-down list
- 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
- Copy the Install-Package command from the public registry (NuGet.org).
- Select Tools then NuGet Package Manager to open the NuGet package manager.
- Paste the command into the Package Manager Console and select run.