title | description | ms.assetid | ms.author | ms.reviewer | author | ms.topic | ms.date | monikerRange | recommendations |
---|---|---|---|---|---|---|---|---|---|
Restore NuGet packages with Azure Pipelines |
Learn how to restore your NuGet packages with Classic and YAML Pipelines. |
C3D7008E-7C23-49A4-9642-E5906DAE3BAD |
rabououn |
rabououn |
ramiMSFT |
how-to |
11/12/2024 |
<= azure-devops |
true |
[!INCLUDE version-lt-eq-azure-devops]
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.
-
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.
Note
If you're using Ubuntu 24.04 or higher, you must use the NuGetAuthenticate
task with the .NET CLI instead of the nuget.exe. See Support for newer Ubuntu hosted images for more details.
-
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>
-
Sign in to your Azure DevOps organization, and then navigate to your project.
-
Select Pipelines, select your pipeline definition, and then select Edit.
-
Select + to add a new task. Add the NuGet tool installer, NuGet Authenticate, and Command line tasks to your pipeline. Leave the NuGet tool installer and NuGet Authenticate tasks with their default settings and configure the Command line task as follows:
- Display name: Restore.
- Script:
nuget.exe restore <SOLUTION_PATH>
-
Select Save & queue when you're done.
Note
Make sure that The NuGet Gallery upstream is enabled in your feed. See Enable upstream sources in an existing feed for details.
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.
-
Navigate to your Azure DevOps organization, and then select User settings > Personal Access Tokens.
:::image type="content" source="media/pat.png" alt-text="Screenshot showing how to create a personal access token.":::
-
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.
:::image type="content" source="media/create-new-pat-updated.png" alt-text="A screenshot showing how to create a personal access token with packaging read permissions.":::
-
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.
:::image type="content" source="media/new-service-connection-nuget-restore.png" alt-text="A screenshot showing how to create a new NuGet service connection.":::
-
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
-
Sign in to your Azure DevOps organization, and then navigate to your project.
-
Select Pipelines, select your pipeline definition, and then select Edit.
-
Select + to add a new task. Add the NuGet tool installer, NuGet Authenticate, and Command line tasks to your pipeline. Leave the NuGet tool installer with its default settings and configure the other tasks as follows:
-
NuGet Authenticate task: Select your service connection from the Service connection credentials for feeds outside this organization dropdown menu.
-
Command line task:
- Display name: Restore.
- Script:
nuget.exe restore <SOLUTION_PATH>
-
-
Select Save & queue when you're done.