The question delves into the distinction between two NuGet restore commands within an Azure build pipeline:

1. NuGetCommand@2 Task:

task: NuGetCommand@2
restoreSolution: '$(solution)’

This task is utilized for installing and updating NuGet package dependencies, or packaging and publishing NuGet packages. It employs NuGet.exe and functions with .NET Framework applications.

2. DotNetCoreCLI@2 Task:

task: DotNetCoreCLI@2
  command: 'restore'
  projects: '$(solution)'
  feedsToUse: 'select'

This task utilizes dotnet restore, which internally uses a version of NuGet.exe packaged with the .NET Core SDK. dotnet restore solely restores packages specified in the .NET Core project’s .csproj files.

The difference lies in the scope of dependency resolution:

  • NuGetCommand@2 is more versatile, suitable for handling dependencies beyond .NET Core projects, such as Microsoft .NET Framework projects or those specified in package.json.
  • DotNetCoreCLI@2 is specialized for .NET Core projects and works directly with .csproj files.

Regarding feedsToUse: ‘select’, it indicates selecting packages cached in Azure Artifacts with upstream sources. This is essential for restoring packages from an external custom feed. Conversely, when such packages aren’t required, the path to the .csproj file(s) should be specified directly in the projects parameter, as shown in the latter example:

- task: DotNetCoreCLI@2
  displayName: 'dotnet restore'
    command: restore
    projects: '**/*.csproj'

This specifies that all .csproj files within the repository should be considered for package restoration.

For further details and syntax, relevant links from Microsoft documentation are provided.

Support On Demand!