0
0
Azurecloud~5 mins

Azure Artifacts for packages - Commands & Configuration

Choose your learning style9 modes available
Introduction
Azure Artifacts helps you store and share code packages like libraries or tools in one place. It solves the problem of managing and distributing these packages safely across your team or projects.
When you want to share reusable code libraries between different projects in your team.
When you need a private place to store packages that only your organization can access.
When you want to control which versions of packages your projects use to avoid errors.
When you want to automate package publishing and consumption in your build pipelines.
When you want to use popular public packages but cache them privately for faster builds.
Config File - nuget.config
nuget.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="AzureArtifacts" value="https://pkgs.dev.azure.com/example-org/_packaging/example-feed/nuget/v3/index.json" />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
</configuration>

This nuget.config file tells your project where to find packages. The AzureArtifacts source points to your private feed in Azure Artifacts, and nuget.org is the public package source. This setup lets you use both private and public packages seamlessly.

Commands
This command creates a new package feed named 'example-feed' in your Azure DevOps project. A feed is where your packages will be stored and shared.
Terminal
az artifacts feed create --name example-feed --project example-project --organization https://dev.azure.com/example-org
Expected OutputExpected
{ "name": "example-feed", "project": { "id": "12345678-1234-1234-1234-123456789abc", "name": "example-project" }, "url": "https://pkgs.dev.azure.com/example-org/_packaging/example-feed/nuget/v3/index.json" }
--name - Sets the name of the new feed
--project - Specifies the Azure DevOps project
--organization - Specifies the Azure DevOps organization URL
This command uploads your package files from the local folder './package-folder' to the 'example-feed' in Azure Artifacts with the name 'my-package' and version '1.0.0'.
Terminal
az artifacts universal publish --organization https://dev.azure.com/example-org --feed example-feed --name my-package --version 1.0.0 --path ./package-folder
Expected OutputExpected
Uploading package 'my-package' version '1.0.0' to feed 'example-feed'... Upload completed successfully.
--feed - Specifies the target feed for the package
--name - Sets the package name
--version - Sets the package version
This command restores all packages for your project using the sources defined in 'nuget.config', including your Azure Artifacts feed.
Terminal
nuget restore -ConfigFile nuget.config
Expected OutputExpected
Restoring packages for project... All packages restored successfully.
-ConfigFile - Specifies the NuGet configuration file to use
This command downloads the package 'my-package' version '1.0.0' from the 'example-feed' into the local folder './downloaded-package'.
Terminal
az artifacts universal download --organization https://dev.azure.com/example-org --feed example-feed --name my-package --version 1.0.0 --path ./downloaded-package
Expected OutputExpected
Downloading package 'my-package' version '1.0.0' from feed 'example-feed'... Download completed successfully.
--feed - Specifies the feed to download from
--name - Specifies the package name
--version - Specifies the package version
Key Concept

If you remember nothing else from this pattern, remember: Azure Artifacts lets you safely store and share code packages in private feeds that your projects can easily access.

Common Mistakes
Not configuring the package source URL correctly in nuget.config
Your project won't find the private packages and will fail to restore them.
Add the exact Azure Artifacts feed URL to nuget.config under <packageSources>.
Trying to publish packages without proper permissions or authentication
The upload will fail because Azure DevOps requires you to be signed in and authorized.
Sign in with 'az login' and ensure you have permissions to publish to the feed.
Using inconsistent package versions between publish and restore commands
Your project may try to restore a version that does not exist, causing errors.
Keep package version numbers consistent and update them properly in all commands.
Summary
Create a private feed in Azure Artifacts to store your packages.
Configure your project to use the feed by updating nuget.config with the feed URL.
Publish packages to the feed using Azure CLI commands.
Restore and download packages from the feed to use them in your projects.