DotNetCoreCLI 还原与 NuGetCommand 还原

问题描述

我试图了解 Azure 构建管道中两个 nuget restore 命令之间的区别:

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

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

我试图理解,但在微软页面上,我所看到的是可以同时使用两者 - 我真的找不到任何说明差异的内容。 (我也不太明白 FeedsToUse: 'select' 语句)

而且,作为第二个问题,后者和

有什么区别
- task: DotNetCoreCLI@2
  inputs:
    command: restore
    projects: '**/*.csproj'

鉴于该解决方案包含所有 csproj(且仅 csproj)?

解决方法

Nuget 任务用于安装和更新 NuGet 包依赖项,或打包和发布 NuGet 包。使用 NuGet.exe 并与 .NET Framework 应用程序配合使用。 对于 .NET Core 和 .NET Standard 应用,请使用 .NET Core 任务

dotnet restore 在内部使用与 .NET Core SDK 一起打包的 NuGet.exe 版本。 dotnet restore 只能还原 .NET Core 项目 .csproj 文件中指定的包。如果您的解决方案中还有 Microsoft .NET Framework 项目或使用 package.json 指定依赖项,则还必须使用 NuGet 任务来恢复这些依赖项。

在 .NET Core SDK 2.0 及更高版本中,运行其他命令(例如 dotnet build)时,包会自动恢复。但是,如果您使用经过身份验证的提要,则可能仍需要使用 .NET Core 任务来还原包。

关于 feedsToUse: 'select',当包缓存在带有上游源的 Azure Artifacts 中时,您应该使用 feedsToUse: 'select',并指定 vstsFeed: xxxx。检查以下语法(如果要从外部自定义提要恢复包,请使用 feedsToUse: 'config',并指定 nugetConfigPathexternalFeedCredentials):

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

当您不需要在 Azure Artifacts 或外部自定义源中缓存的包时,请使用以下语法(您应该指定要在 projects 中使用的 csproj 文件的路径,而不是解决方案的路径):

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

有用的链接: