Restore NuGet packages with Azure Pipelines (YAML/Classic)
Azure DevOps Services | Azure DevOps Server 2022 - Azure DevOps Server 2019
With NuGet Package Restore you can install all your project's dependency without needing to store them in source control. This allows for a cleaner development environment and a smaller repository size. You can restore your NuGet packages using the NuGet restore task, the NuGet CLI, or the .NET Core CLI. This article will guide you through restoring your NuGet packages using both Classic and YAML Pipelines.
Prerequisites
Create an Azure DevOps organization and a project if you haven't already.
Create a new feed if you don't have one already.
If you're using a self-hosted agent, make sure that it has the .NET Core SDK (2.1.400+) and NuGet (4.8.0.5385+) installed.
Restore NuGet packages from a feed in the same organization
Sign in to your Azure DevOps organization, and then navigate to your project.
Select Pipelines, and then select your pipeline definition.
Select Edit, and then add the following snippet to your YAML pipeline.
steps: - task: NuGetAuthenticate@1 - task: NuGetToolInstaller@1 inputs: versionSpec: '*' checkLatest: true - script: nuget restore <SOLUTION_PATH>
Note
Make sure that The NuGet Gallery upstream is enabled in your feed. See Enable upstream sources in an existing feed for details.
Restore NuGet packages from a feed in another organization
To restore NuGet packages from a feed in a different Azure DevOps organization, you must first create a personal access token then use it to set up a NuGet service connection.
Create a personal access token
Navigate to your Azure DevOps organization, and then select User settings > Personal Access Tokens.
Create a new personal access token with Packaging* > Read scope. Copy your PAT as you'll need it in the following section.
Select Create when you're done.
Create a service connection
Sign in to the Azure DevOps organization where your pipeline will run, and then navigate to your project.
Navigate to your Project settings > Service connections.
Select New service connection, select NuGet, and then select Next.
Select External Azure DevOps Server as the Authentication method, and then enter your target Feed URL. Paste the Personal Access Token you created earlier, provide a name for your service connection, and check Grant access permission to all pipelines if applicable to your scenario.
Select Save when you're done.
Restore packages
Sign in to your Azure DevOps organization, and then navigate to your project.
Select Pipelines, and then select your pipeline definition.
Select Edit, and then add the following snippet to your YAML pipeline.
- task: NuGetToolInstaller@1 inputs: versionSpec: '*' checkLatest: true - task: NuGetAuthenticate@1 inputs: nuGetServiceConnections: <SERVICE_CONNECTION_NAME> - script: | nuget.exe restore <SOLUTION_PATH> displayName: Restore