DotNetCoreCLI restore vs NuGetCommand restore
Asked Answered
A

1

26

I am trying to understand the difference between the two nuget restore commands in Azure build pipeline:

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

and

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

I have tried to understand but at microsoft pages all I see is that one can use both - I can't really find anything stating what the differences are. (I do not really understand the feedsToUse: 'select' statement either)

And, as a second question, what is the difference between the latter and

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

Given that the solution contains all of the csproj (and only csproj)?

Adynamia answered 25/2, 2021 at 22:48 Comment(0)
L
37

Nuget task is used to install and update NuGet package dependencies, or package and publish NuGet packages. Uses NuGet.exe and works with .NET Framework apps. For .NET Core and .NET Standard apps, use the .NET Core task.

dotnet restore internally uses a version of NuGet.exe that is packaged with the .NET Core SDK. dotnet restore can only restore packages specified in the .NET Core project .csproj files. If you also have a Microsoft .NET Framework project in your solution or use package.json to specify your dependencies, you must also use the NuGet task to restore those dependencies.

In .NET Core SDK version 2.0 and newer, packages are restored automatically when running other commands such as dotnet build. However, you might still need to use the .NET Core task to restore packages if you use an authenticated feed.

Regarding feedsToUse: 'select', when the packages cached in Azure Artifacts with upstream sources, you should use feedsToUse: 'select', and specify vstsFeed: xxxx. Check the following syntax (If you want to restore packages from an external custom feed, use feedsToUse: 'config', and specify nugetConfigPath and externalFeedCredentials):

#feedsToUse: # Options: select, config
#vstsFeed: # Required when feedsToUse == Select
#nugetConfigPath: # Required when feedsToUse == Config
#externalFeedCredentials: # Optional

When you don't need packages cached in Azure Artifacts, or from an external custom feed, use the following syntax (You should specify the path to the csproj file(s) to use in projects, not the path to the solution):

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

Useful links:

Leipzig answered 26/2, 2021 at 9:17 Comment(1)
This type of hard to discover incompatibility makes using MS ecosystem so frustrating. Isn't the whole point of a dedicated Nuget pipeline task to hide this type of thing?Edric

© 2022 - 2024 — McMap. All rights reserved.