When we develop software we use a lot of packages, some are top-notch open source and others can be internal. Examples are packages that are used by teams for purposes that are common across projects or packages that are required by enterprise to be included in projects.

Use cases vary but it is evident the need of hosting these packages and Azure Artifacts is one of the available services that deal with that. In this post I will document

  • Creating a new private feed
  • Pushing packages to the feed via a CD pipeline
  • Accessing the feed via Nuget Package Manager in Visual Studio
Azure Artifacts is a service where you can create package feeds to publish and consume the following package types: Maven. npm. NuGet. Python

The first step is to create the new feed, click on the Artifacts in Azure DevOps and locate the created feed button, In the pop-up window enter a name for the feed and select it's visibility and scope

Now that the feed has been created it is time to publish a package to it. A package can be published either through visual studio and the package manager console which in my opinion is a lot of boilerplate work or a release pipeline can be created / edited and push the package to the feed. I prefer the latter option as If you're doing CI / CD you already have a pipeline for you project.

The CD pipeline consists of four tasks, build & test tasks are automatically added when you set-up a pipeline for a .NET project so let's focus on the next two.

project release pipeline
The dotnet pack command builds the project and creates NuGet packages. The result of this command is a NuGet package (that is, a .nupkg file).
The nuget push command pushes a package to a package source and publishes it.

The nuget push task is also used to specify the feed to which the package must be published. Once the tasks have been added queue the pipeline to deploy the package.

nuget push task
Release pipeline

Once the pipeline successfully executes, switch back to the Artifacts dashboard and the recently pushed packages should appear there.

Updated feed

Last step is to add the newly created feed to Nuget;s package sources in visual studio. From the feed page click on Connect to feed and then select nuget or dotnet

You will be presented an XML that can be added to the project. The XML contains a key with the location of the feed. Copy the url.

<?xml version="1.0" encoding="utf-8"?>
    <clear />
    <add key="MyProject" value="https://<myorganization>.pkgs.visualstudio.com/_packaging/myproject/nuget/v3/index.json" />

Open Visual Studio and navigae to Tools > Options > Nuget Package Manager >Package Sources and create a new source with the URL from above.

Nuget Package Sources

Now it's time to validate that the package is visible and indeed hosted in the feed. Right click on any project and open the manage packages screen. On the package source drop down select the source that was added. The package pushed from the pipeline should now be visible along with other packages that it depended on.

Listing feeds packages

In the next post I will document the process of restoring the packages in a CI pipeline as it requires authentication against the feed.

Thanks for reading.