Publish a package to an Azure Artifacts feed

Azure Artifacts enables developers to efficiently manage all their dependencies from a single feed. Feeds in Azure Artifacts serve as organizational repositories for storing, managing, and sharing your packages within your team, across organizations, or publicly on the internet. Azure Artifacts feeds support a wide range of package types, including NuGet, npm, Python, Maven, Cargo, and Universal Packages.

This article walks you through the process of publishing your first package to an Azure Artifacts feed. You also have the option to use GitHub Copilot to streamline this process and explore the capabilities of the GitHub Copilot Chat in Visual Studio Code.

Prerequisites

Create a feed

  1. Sign in to your Azure DevOps organization, and then navigate to your project.

  2. Select Artifacts, and then select Create Feed.

  3. Provide a descriptive Name for your feed and set its Visibility (who can view packages in your feed). Define the Scope of your feed, and if you want to include packages from public sources, check the Upstream sources checkbox.

  4. Select Create when you're done.

    Screenshot that shows how to create a new feed in Azure DevOps Services.

  1. Sign in to your Azure DevOps server, and then navigate to your project.

  2. Select Artifacts, and then select Create Feed.

  3. Provide a descriptive Name for your feed and set its Visibility (who can view packages in your feed). Define the Scope of your feed, and if you want to include packages from public sources, check the Upstream sources checkbox.

  1. Select Create when you're done.

    Screenshot that shows how to create a new feed in Azure DevOps Server 2022.

  1. Select Create when you're done.

    Screenshot that shows how to create a new feed in Azure DevOps Server 2020.

Prepare the code

Follow these steps to create a basic Class Library project from the command line, set up your package's metadata, and generate a NuGet package:

  1. On your local machine, create a new folder and give it a name.

  2. Open a command prompt window and navigate to the folder you created.

  3. Run the following command to create a new Class Library project:

    dotnet new classlib
    
  4. Open your csproj file and add your package metadata within the <PropertyGroup> tag. Your file structure should resemble the following:

    <Project Sdk="Microsoft.NET.Sdk">
    
      <PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
        <RootNamespace>demo_class_library</RootNamespace>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
    
        <PackageId>YOUR_PACKAGE_NAME</PackageId>
        <Version>YOUR_PACKAGE_VERSION</Version>
        <Authors>YOUR_NAME</Authors>
        <Company>YOUR_COMPANY</Company>
    
      </PropertyGroup>
    
    </Project>
    
  5. Run the following command to package your project and generate a .nupkg artifact. your NuGet package is generated in the bin\release directory.

    dotnet pack
    

Connect to a feed

  1. Select Artifacts and then select your feed from the dropdown menu.

  2. Select Connect to feed, and then select dotnet from the NuGet section.

  3. Follow the instructions in the Project setup to set up your nuget.config file. The structure of your file should look similar to this:

    • Project-scoped feed:

      <?xml version="1.0" encoding="utf-8"?>
      <configuration>
        <packageSources>
          <clear />
          <add key="<FEED_NAME>" value="https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/nuget/v3/index.json" />
        </packageSources>
      </configuration>
      
    • Organization-scoped feed:

      <?xml version="1.0" encoding="utf-8"?>
      <configuration>
        <packageSources>
          <clear />
          <add key="<FEED_NAME>" value="https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/_packaging/<FEED_NAME>/nuget/v3/index.json" />
        </packageSources>
      </configuration>
      
  1. Sign in to your Azure DevOps collection, and then navigate to your project.

  2. Select Artifacts, and then select your feed from the dropdown menu.

  3. Select Connect to Feed, and then select dotnet from the left navigation pane.

  4. Follow the instructions in the Project setup section to configure your nuget.config file and connect to your feed.

    A screenshot that shows how to connect to a feed with dotnet in Azure DevOps Server 2020 and 2022.

Tip

You can ask GitHub Copilot, "how to add a new package source to an existing nuget.config file". Copilot will guide you through using the nuget sources Add command to add your new feed source URL to your nuget.config file.

Publish packages

Run the following command from your project directory to publish your package. The ApiKey is required, but you can use any string value when publishing to an Azure Artifacts feed.

dotnet nuget push --source <FEED_NAME> --api-key az <PACKAGE_PATH>

Next steps