Skip to content

Latest commit

 

History

History
168 lines (113 loc) · 6.96 KB

nuget-exe.md

File metadata and controls

168 lines (113 loc) · 6.96 KB
title description ms.assetid ms.service ms.topic ms.date monikerRange recommendations
Connect to an Azure Artifacts feeds with NuGet CLI
Learn how to connect to Azure Artifacts feeds with NuGet CLI.
10665DBC-846E-4192-8CAB-D5A4C6E40C65
azure-devops-artifacts
how-to
04/08/2025
<= azure-devops
true

Connect to an Azure Artifacts feed (NuGet.exe)

[!INCLUDE version-lt-eq-azure-devops]

Azure Artifacts enables developers to download NuGet packages from various sources such as private feeds and public registries. You can publish packages to private feeds and control access, or create public feeds to share them openly. This article guides you through authenticating with to your Azure Artifacts feed.

Prerequisites

Product Requirements
Azure DevOps - An Azure DevOps organization.
- An Azure DevOps project.
- An Azure Artifacts feed.
- Download and install the Azure Artifacts Credential Provider.
- Install the latest NuGet version.

Project setup

::: moniker range="azure-devops"

  1. Sign in to your Azure DevOps organization, and then navigate to your project.

  2. Select Artifacts, and then select your feed from the dropdown menu.

  3. Select Connect to feed, and then select NuGet.exe from the left.

  4. Add a nuget.config file to your project, place it in the same folder as your csproj or sln file, and then paste the provided snippet into it. Your nuget.config file should resemble the following:

    • 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>
    • 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>

::: moniker-end

::: moniker range="azure-devops-2020 || azure-devops-2022"

  1. Sign in to your Azure DevOps collection, and then navigate to your project.

  2. Select Artifacts, and then select your feed from the dropdown menu.

  3. Select Connect to Feed, and then select NuGet.exe from the left navigation pane.

  4. Add a nuget.config file to your project, place it in the same folder as your csproj or sln file, and then paste the snippet provided in the Project setup section into your file.

::: moniker-end

Note

The Azure Artifacts Credential Provider requires NuGet version 4.8.0.5385 or higher. For optimal performance, Azure Artifacts recommends using NuGet version 5.5.x or later, as it includes crucial bug fixes related to cancellations and timeouts.

::: moniker range="azure-devops"

Legacy project setup

If you're using an older version of NuGet, follow the instructions below to connect to your feed:

  1. Sign in to your Azure DevOps organization, and then navigate to your project.

  2. Select Artifacts and then select your feed from the dropdown menu.

  3. Select Connect to feed, and then select NuGet.exe from the left.

  4. Copy your source URL from the Project setup section, and then replace /v3/index.json with /v2. Your updated source URL should look like one of the following:

    • Project-scoped feed:

      https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/nuget/v2
      
    • Organization-scoped feed:

      https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/_packaging/<FEED_NAME>/nuget/v2
      
  5. Create a Personal Access Token, make sure you scope it to the right organization you want to access, and then select one of the following scopes based on your needs: Packaging (read), Packaging (read and write), or Packaging (read, write, and manage).

  6. Run the following command in a command prompt window to add your feed source to your nuget.config file:

    nuget sources add -name <FEED_NAME> -source <SOURCE_URL> -username <ANY_STRING_BUT_NOT_NULL> -password <YOUR_PERSONAL_ACCESS_TOKEN>
    
  7. If your organization is connected to Microsoft Entra ID, you must first authenticate with your AD credentials, and then add your personal access token using the setapikey command:

    nuget sources add -name <FEED_NAME> -source <SOURCE_URL> -username <AZURE_ACTIVE_DIRECTORY_USERNAME> -password <AZURE_ACTIVE_DIRECTORY_PASSWORD>
    
    nuget setapikey <YOUR_PERSONAL_ACCESS_TOKEN> -source <SOURCE_URL> 
    

::: moniker-end

Authenticate using Service Principals

To authenticate with an Azure Artifacts feed using a service principal, set the ARTIFACTS_CREDENTIALPROVIDER_FEED_ENDPOINTS environment variable as shown below.

This specifies your feed URL, the service principal's application (client) ID, and either the subject name or the file path of the service principal certificate (only one of these two is required).

$env:ARTIFACTS_CREDENTIALPROVIDER_FEED_ENDPOINTS = @'{
    "endpointCredentials": [
        {
            "endpoint": "<FEED_URL>",
            "clientId": "<SERVICE_PRINCIPAL_APPLICATION_(CLIENT)_ID>",
            "clientCertificateSubjectName": "<SERVICE_PRINCIPAL_CERTIFICATE_NAME>",
            "clientCertificateFilePath": "<SERVICE_PRINCIPAL_CERTIFICATE_PATH>"
        }
    ]
}
'@
export ARTIFACTS_CREDENTIALPROVIDER_FEED_ENDPOINTS='{
    "endpointCredentials": [
        {
            "endpoint": "<FEED_URL>",
            "clientId": "<SERVICE_PRINCIPAL_APPLICATION_(CLIENT)_ID>",
            "clientCertificateSubjectName": "<SERVICE_PRINCIPAL_CERTIFICATE_NAME>",
            "clientCertificateFilePath": "<SERVICE_PRINCIPAL_CERTIFICATE_PATH>"
        }
    ]
}'

Related content