Azure Artifacts allows you to host your own private package feeds for various package managers like NuGet, npm, Maven, and Python. This tutorial will guide you through the process of consuming a package that you've published to an Azure Artifacts feed from your development projects.
Before you can consume packages, your development environment needs to be configured to point to your Azure Artifacts feed. This usually involves setting up a credentials provider or directly configuring your package manager.
For NuGet, the recommended way to authenticate is by using the Azure Artifacts Credential Provider. This tool automatically handles authentication for Visual Studio, `dotnet CLI`, and `msbuild`.
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201
# Download and install the credential provider from the official Azure DevOps documentation.
# Refer to the documentation for platform-specific installation steps.
Once the credential provider is installed, you can add your feed to your NuGet configuration file. This can be a global `NuGet.Config` or one specific to your solution.
<configuration>
<packageSources>
<!-- Add this to your nuget.config file -->
<add key="MyAzureArtifactsFeed" value="https://pkgs.dev.azure.com/{your-organization}/{your-project}/_packaging/{your-feed-name}/nuget/v3/index.json" />
</packageSources>
</configuration>
For npm, you can configure your `.npmrc` file to point to your Azure Artifacts feed and handle authentication.
Create or edit the `.npmrc` file in your project's root directory (or your user directory for global configuration).
# .npmrc
registry=https://pkgs.dev.azure.com/{your-organization}/{your-project}/_packaging/{your-feed-name}/npm/registry/
always-auth=true
You can use a Personal Access Token (PAT) with the 'Packaging (Read)' scope. Log in using the PAT:
npm login --registry https://pkgs.dev.azure.com/{your-organization}/{your-project}/_packaging/{your-feed-name}/npm/registry/ --scope=@your-scope
You'll be prompted for a username (use `anything`, like `az`), password (your PAT), and email (use `anything`).
For Python packages, you'll configure `pip` to use your Azure Artifacts feed.
Create or edit `pip.conf` (Linux/macOS) or `pip.ini` (Windows) in your user's config directory.
# pip.conf or pip.ini
[global]
index-url = https://pkgs.dev.azure.com/{your-organization}/{your-project}/_packaging/{your-feed-name}/pypi/simple/
extra-index-url = https://pypi.org/simple/
You can use a PAT with the 'Packaging (Read)' scope. Store your credentials securely, for example, in the same config file or using an environment variable, and `pip` will use them.
# In pip.conf or pip.ini (use with caution, consider environment variables)
[global]
index-url = https://{username}:{pat}@pkgs.dev.azure.com/{your-organization}/{your-project}/_packaging/{your-feed-name}/pypi/simple/
extra-index-url = https://pypi.org/simple/
Alternatively, install the Azure Artifacts credential provider for Pip.
Once your feed is configured and authenticated, consuming a package is as simple as using your standard package manager commands.
To install a package from your feed using the .NET CLI:
dotnet add package YourPackageName --version 1.0.0
Or using the Package Manager Console in Visual Studio:
Install-Package YourPackageName -Version 1.0.0
NuGet will automatically look for `YourPackageName` in the feeds configured in your `nuget.config`, including your Azure Artifacts feed.
To install a package from your feed:
npm install your-package-name
If your feed is scoped correctly (e.g., using `@your-scope/your-package-name`), npm will resolve it from your configured Azure Artifacts registry.
To install a package from your feed:
pip install your-package-name
Pip will search your configured `index-url` and `extra-index-url` sources to find and install the package.
If you encounter authentication issues, double-check your feed URL, PAT permissions, and ensure the credential provider is correctly installed and configured for your environment.