如何在 Azure Pipelines 中添加 NuGet 包源?

问题描述

我最近在使用 Azure Pipelines,我的构建过程中有一个 NuGet 任务。此进程总是失败,因为 NuGet 源中没有名为“BotUtility”的包。这是因为此包是我自己创建的,并且仅存储在 Azure Artifacts 中。

##[error] nuget 命令失败,退出代码 (1) 和错误(NU1101:无法找到包 BotUtility。源中不存在具有此 ID 的包:NuGetorg

Build Pipeline 是否可以在 Azure Artifacts 中访问此包,如果可以,我该如何实现?我可以在流水线配置中添加包源吗?

enter image description here

有更详细的错误位置截图。

enter image description here

这是我当前版本的构建管道。

解决方法

好吧,您可以将 nuget 提要添加到 nuget 任务中;

enter image description here

另一种方法是在您的项目中定义一个 nuget.config,然后在那里添加您的包:

<?xml version="1.0" encoding="utf-8"?>

<configuration>

  <!-- NuGet packages are now stored globally,see: https://stackoverflow.com/a/35809007/4122889 -->
  <!-- see: https://stackoverflow.com/a/53451805/4122889 -->
  <config>
    <add key="globalPackagesFolder" value=".\Packages" />
    <add key="repositoryPath" value=".\Packages" />
  </config>

  <!-- Setup for local packages,not in a nuget source -->
  <packageSources>
    <add key="MY_FEED" value="https://pkgs.dev.azure.com/org/project/_packaging/MY_FEED/nuget/v3/index.json" />
    <!--<add key="LocalPackages" value="./LocalPackages" />-->

  </packageSources>
  <activePackageSource>
    <!-- this tells that all of them are active -->
    <!--<add key="All" value="(Aggregate source)" />-->
  </activePackageSource>

</configuration>