Introduction to Azure Artifacts
Azure Artifacts is a service that allows you to create, host, and share package feeds with your team. It integrates seamlessly with Azure Pipelines, enabling efficient management of your software dependencies. You can host public and private packages from various sources, including NuGet, npm, Maven, Python (PyPI), and universal packages.
This tutorial will guide you through setting up and using Azure Artifacts effectively in your development workflow.
Getting Started: Creating Your First Feed
A feed is a collection of packages. Let's create a new feed to store your project's dependencies.
- Navigate to your Azure DevOps project.
- Select Artifacts from the left-hand navigation menu.
- Click the + Create Feed button.
- Provide a name for your feed (e.g.,
MyProjectFeed
). - Choose the visibility (Private or Public). For most internal projects, Private is recommended.
- Configure upstream sources if you want to proxy packages from public registries like NuGet.org or npmjs.com.
- Click Create.
You'll now see your new feed, ready to host packages.
Connecting to Your Feed
To publish or consume packages, you need to configure your local development environment or build agents to connect to your Azure Artifacts feed.
For NuGet:
Use the Azure Artifacts Credential Provider. Follow the instructions on the feed's connection page to install and configure it.
dotnet nuget add source "https://pkgs.dev.azure.com/YOUR_ORG/YOUR_PROJECT/_packaging/YOUR_FEED/nuget/v3/index.json" --name AzureArtifacts
For npm:
Configure your .npmrc
file:
registry=https://pkgs.dev.azure.com/YOUR_ORG/YOUR_PROJECT/_packaging/YOUR_FEED/npm/registry/
Ensure you have the vsts-npm-auth
tool installed for authentication.
For other package types, refer to the specific connection instructions provided within Azure Artifacts.
Publishing Packages
Once connected, you can publish your custom packages to your feed.
Publishing a NuGet Package:
dotnet pack --configuration Release
dotnet nuget push --source AzureArtifacts --api-key any-string YourPackage.1.0.0.nupkg
Publishing an npm Package:
npm publish --registry https://pkgs.dev.azure.com/YOUR_ORG/YOUR_PROJECT/_packaging/YOUR_FEED/npm/registry/
Remember to update your package versioning appropriately.
Consuming Packages
Your projects can now reference packages from your Azure Artifacts feed.
Consuming a NuGet Package:
Add a PackageReference
to your .csproj
file:
<ItemGroup>
<PackageReference Include="YourPackage" Version="1.0.0" />
</ItemGroup>
Ensure your NuGet client is configured to use the Azure Artifacts feed.
Consuming an npm Package:
Install the package:
npm install your-package
The .npmrc
configuration will automatically direct npm to your feed.
Upstream Sources
Upstream sources allow your feed to act as a proxy for public package registries like NuGet.org, npmjs.com, or Maven Central. This means if a package isn't found in your feed, Azure Artifacts will try to retrieve it from the configured upstream sources and cache it in your feed.
Benefits:
- Improved build reliability: Your builds won't fail if a public registry is temporarily unavailable.
- Centralized dependency management: All your project dependencies, public and private, are managed in one place.
- Bandwidth savings: Frequently used public packages are downloaded only once.
Advanced Features
- Permissions: Control who can view, publish, and manage your feeds.
- Retention Policies: Automatically clean up older package versions to manage storage.
- Upstream Naming: Customize how upstream packages are represented in your feed.
- Security: Integrate with Azure Active Directory for robust authentication and authorization.