Bemærk
Adgang til denne side kræver godkendelse. Du kan prøve at logge på eller ændre mapper.
Adgang til denne side kræver godkendelse. Du kan prøve at ændre mapper.
Azure DevOps Services | Azure DevOps Server | Azure DevOps Server 2022
This article walks you through connecting to your feed and publishing packages by using two authentication flows: the Azure Artifacts Credential Provider for feeds in your own organization, and a personal access token (PAT) for feeds hosted in a different organization.
Prerequisites
- An Azure DevOps organization.
- An Azure DevOps project.
- An Azure Artifacts feed.
- nuget.exe version
4.8.0.5385or later. Azure Artifacts recommends NuGet5.5.xor later for the best compatibility and reliability. - To publish packages, you must be a Feed Publisher (Contributor) or higher.
Set up the Azure Artifacts Credential Provider
The Azure Artifacts Credential Provider enables secure authentication to your Azure Artifacts feeds. To use it with nuget.exe, you must first add it to NuGet’s plugin search path. For details, see Plugin Installation and discovery. Once the plugin is added, follow the installation steps for your operating system:
Use one of the following methods to install the Azure Artifacts Credential Provider:
Manual installation
Download the latest Microsoft.NetFx48.NuGet.CredentialProvider.zip release.
Extract the zip file.
Copy the
netfxfolder from the extracted archive to%UserProfile%/.nuget/plugins/. Thenetfxfolder is required for nuget.exe compatibility.
Install using the helper script
Alternatively, you can use the automated helper script for a streamlined installation. Ensure you have PowerShell 5.1 or later, and then run:
iex "& { $(irm https://aka.ms/install-artifacts-credprovider.ps1) } -AddNetfx"
For more information, see the Azure Artifacts Credential Provider repository.
Connect to a feed
Before you can publish your packages, set up your project and connect to your feed as follows:
Sign in to your Azure DevOps organization, and then navigate to your project.
Select Artifacts, and then select your feed from the dropdown menu.
Select Connect to feed, and then select NuGet.exe from the left navigation pane.
Add a
nuget.configfile to your project, in the same folder as your.csprojor.slnfile. Paste the provided XML snippet into your file. The snippet should look like the following:Organization-scoped feed:
<?xml version="1.0" encoding="utf-8"?> <configuration> <packageSources> <clear /> <add key="<SOURCE_NAME>" value="https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/_packaging/<FEED_NAME>/nuget/v3/index.json" /> </packageSources> </configuration>Project-scoped feed:
<?xml version="1.0" encoding="utf-8"?> <configuration> <packageSources> <clear /> <add key="<SOURCE_NAME>" value="https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/nuget/v3/index.json" /> </packageSources> </configuration>
Sign in to your Azure DevOps server, and then navigate to your project.
Select Artifacts, and then select your feed.
Select Connect to Feed, and then select NuGet.exe from the left navigation pane.
Add a
nuget.configfile to your project, in the same folder as your.csprojor.slnfile, and then paste the provided XML snippet into your file.
Publish to a feed in the same organization
After you configure nuget.config and authenticate by using the Azure Artifacts Credential Provider, run the following command to publish a package to your feed. Replace the placeholders with the appropriate values:
nuget push <PACKAGE_PATH> -Source https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/nuget/v3/index.json -ApiKey <ANY_STRING>
Example:
nuget push MyPackage.5.0.2.nupkg -Source https://pkgs.dev.azure.com/MyOrg/MyProject/_packaging/MyFeed/nuget/v3/index.json -ApiKey AZ
Note
The Azure Artifacts Credential Provider handles the real authentication for the push, but NuGet still requires an -ApiKey value to accept the command. Azure Artifacts ignores the value you provide, so any nonempty string works.
Publish to a feed in another organization
If the target feed is in a different Azure DevOps organization, create a PAT in that organization and add the feed as a source in your nuget.config file.
Create a personal access token (PAT) in the target organization with Packaging > Read & write scope.
Run the following command to add the feed as a source. This command adds your PAT to
nuget.config, so store the file securely and don't check it into source control.nuget sources Add -Name <SOURCE_NAME> -Source https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/nuget/v3/index.json -UserName <USER_NAME> -Password <PERSONAL_ACCESS_TOKEN> -config <PATH_TO_NUGET_CONFIG_FILE>Publish the package by using the source name you just added.
nuget push <PACKAGE_PATH> -Source <SOURCE_NAME> -ApiKey <ANY_STRING>
Example:
nuget sources Add -Name "MySource" -Source https://pkgs.dev.azure.com/MyOrg/MyProject/_packaging/MyFeed/nuget/v3/index.json -UserName MyUserName -Password YourPersonalAccessToken -config ./nuget.config
nuget push nupkgs/mypackage.1.1.8.nupkg -Source MySource -ApiKey AZ
Note
If your organization uses a firewall or proxy server, allow the Azure Artifacts Domain URLs and IP addresses.
Troubleshooting
Authentication prompt doesn't appear
Ensure the Azure Artifacts Credential Provider is installed and you're using NuGet version 4.8.0.5385 or later. For setup steps, see Connect to Azure Artifacts feeds with NuGet.exe.
Publish fails because the version already exists
Package versions in Azure Artifacts are immutable. After you publish a version, you can't overwrite it or reuse the same version number, even if you delete the package. Update the package version, rebuild the package, and then publish it again.
Publish fails behind a firewall or proxy
Allow the Azure Artifacts Domain URLs and IP addresses, and then retry the publish operation.
Publish fails with a 403 error
This error usually means your account doesn't have publish permissions on the feed. You need at least the Feed Publisher (Contributor) role to push packages. Ask a Feed Owner to update your role, and then try again.