次の方法で共有


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

  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

  4. 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.

  1. Select Build and Release > Packages.

  2. Select your feed from the dropdown menu or create one if you haven't.

  3. Select Connect to feed.

    Connect to feed - TFS

  4. Select NuGet and follow the instruction to connect to your feed.

    Connect to NuGet feed - TFS

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.

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

  1. Select Build and Release, and then select Packages.

  2. Select your feed from the dropdown menu.

  3. Select Connect to feed.

    Connect to feed

  4. Copy your feed's 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.