A Comprehensive Guide to Package Management in Azure DevOps
Azure Artifacts allows you to create, host, and share packages with your team. It integrates seamlessly with Azure DevOps, enabling you to manage dependencies for various package types, including NuGet, npm, Maven, and Python packages.
This section will guide you through setting up and using Azure Artifacts for your projects.
A feed is a repository for your packages. You can create public or private feeds.
In your Azure DevOps project, go to the Artifacts section in the left-hand navigation menu.
Click on the + Create Feed button. This will open a modal window.
Name: Enter a descriptive name for your feed (e.g., MyOrgPackages).
Visibility: Choose the visibility (e.g., Members of my organization).
Upstream sources: You can choose to include public registries like NuGet.org, npmjs.com, or PyPI.org. This allows your feed to act as a proxy and cache for these external packages.
Click Create.
Once your feed is created, you need to configure your development tools to connect to it.
dotnet nuget add source "https://pkgs.dev.azure.com/[YourOrganization]/_packaging/[YourFeedName]/nuget/v3/index.json" --name "[YourFeedName]" --store-password-in-clear-text
Replace [YourOrganization] and [YourFeedName] with your actual Azure DevOps organization and feed names.
You might be prompted for your Azure DevOps credentials. Use a Personal Access Token (PAT) with appropriate permissions (e.g., Packaging Read) for better security.
dotnet restore
In the root of your project, create or modify the .npmrc file.
registry=https://pkgs.dev.azure.com/[YourOrganization]/_packaging/[YourFeedName]/npm/registry/
always-auth=true
You may need to add authentication details depending on your setup, often handled by the azure-devops-cli or a specific npm credential provider.
npm install
Publishing your own packages to Azure Artifacts is straightforward.
dotnet pack --configuration Release
dotnet nuget push bin/Release/[YourPackageName].[YourPackageVersion].nupkg --source "[YourFeedName]" --api-key AzureDevOps
The --api-key value can be anything when pushing to Azure Artifacts, but AzureDevOps is a common convention.
Use the Azure DevOps CLI extension or manually configure authentication in your .npmrc.
npm login --registry https://pkgs.dev.azure.com/[YourOrganization]/_packaging/[YourFeedName]/npm/registry/
You will be prompted for username and password (use a PAT for the password).
npm publish
Upstream sources allow your feed to pull packages from external registries. This acts as a centralized cache for your project dependencies.
npmjs.com, NuGet.org, PyPI.org, or add custom ones.You can manage who can contribute to and consume packages from your feeds:
Contributor (to publish packages) and Reader (to consume packages).Azure Artifacts is a powerful tool for managing your software supply chain within Azure DevOps. By following these steps, you can effectively host and consume packages, improving your team's productivity and the consistency of your build and release pipelines.