如何在 azure devops 管道中从另一个包源安装 nuget 包?

Ala*_*íaz 5 .net azure nuget devops

我正在尝试在 azure 上运行一些 API 测试,我之前已经能够运行我的工件,但是这个特定任务需要一个不在包源中的包:nuget.org,它是来自我工作的公司的包因为,所以当我运行管道时,我收到以下消息:

##[error]The nuget command failed with exit code(1) and error(NU1101: Unable to find package: name of package

我在创建项目时遇到了这个问题,所以我不得不添加包源,我该如何在管道上做到这一点?

Sim*_*ess 7

您可以将nuget.config 文件放置在列出包源的解决方案级别,例如

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="your-nuget" value="https://pkgs.dev.azure.com/example/_packaging/example-nuget/nuget/v3/index.json" />
    <add key="NuGet official package source" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
  <activePackageSource>
    <add key="All" value="(Aggregate source)" />
  </activePackageSource>
</configuration>
Run Code Online (Sandbox Code Playgroud)

请注意,这也适用于 Visual Studio(如果您通过 VS 工具菜单手动添加,您应该能够删除额外的包源)。

然后,根据您的 .net 风格,只需在构建之前恢复包的步骤即可,DotNetCoreCLI@2(命令:restore feedsToUse:'config')或NuGetCommand@2(命令:restore feedsToUse:'config') )。