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内部使用NuGet.exe与 .NET Core SDK 打包在一起的版本。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 中缓存的包或来自外部自定义源的包,请使用以下语法(您应该指定要在 中使用的 csproj 文件projects的路径,而不是解决方案的路径):

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

有用的链接:

  • https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/package/nuget?view=azure-devops
  • https://docs.microsoft.com/en-us/azure/devops/pipelines/ecosystems/dotnet-core?view=azure-devops&tabs=dotnetfive

以上是DotNetCoreCLI还原与NuGetCommand还原的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>