在 Azure DevOps 中使用许可的 NuGet 包

Edg*_*ras 0 nuget-package nuget-package-restore xamarin.forms azure-devops

我已支付通过私人 NuGet 源检索的许可 NuGet 包。当尝试从该源搜索 Visual Studio 中的任何包时,它会提示输入用户名和密码。该应用程序(Xamarin Forms)可以很好地使用这些许可包构建。

另一方面,现在 Azure DevOps 失败了,因为它无法从 nuget.org 恢复块。

经过研究,尝试了两种选择:

选项 1:使用 DevOps 中的“服务连接”通过凭据连接到此源,就像在 Visual Studio 中一样,然后使用 NuGet 还原来选择该服务连接。这会生成一个临时 nuget.config 文件,其完整内容为:<configuration/>并且该任务无法找到丢失的 NuGet。

选项 2:使用 Artifacts,并从本地计算机手动推送。我已从其位置推送了项目引用的文件,但其工件描述末尾附加了“试用版本”。构建仍然失败并出现以下错误:

##[error]The NuGet command failed with exit code(1) and error(NU1101: Unable to find package Infragistics.XF.DV. No packages exist with this id in source(s): 94785e32-5a7b-4923-93b0-abe71c3c1f4c
Run Code Online (Sandbox Code Playgroud)

我认为这两种情况都会失败,因为临时 nuget.config 文件为空。在选项2之后,配置文件被删除,所以我看不到里面到底有什么。

另请注意,使用 Visual Studio 浏览时此源非常慢。

请告知我如何将私有包引入 DevOps?

编辑答案:Nuget 恢复任务,nuget.config 路径为空,因为我预计会自动生成一个与答案内容类似的新路径。我将 Nuget.config 添加到带有 2 个提要的项目源代码中,并且它工作正常。

此外,您还可以在以下位置找到 Visual Studio 全局 Nuget.config:%AppData%\NuGet

Lan*_*SFT 5

请告知我如何将私人包放入 DevOps?

假设您的项目需要的包来自两个提要:公共提要 nuget.org和另一个私有提要:

对于 nuget 恢复任务,如果我们选择Feeds in my Nuget.configin feeds to use,我们可以Credentials for feeds outside this organization/collection在那里进行配置。这就是我们私人饲料所需要的。

(如果您使用 yaml 管道,相关输入为feedsToUsenugetConfigPathexternalFeedCredentials

请按照下列步骤操作:

1.在azure devops存储库中创建一个简单的Nuget.Config文件(与您的解决方案相同的分支):

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="PrivateFeed" value="Url of Your Feed, end with index.json" />
  </packageSources>
</configuration>
Run Code Online (Sandbox Code Playgroud)

将以上内容复制到Nuget.Config文件并保存更改。(或者您可以获取Visual Studio 使用的本地Nuget.Config并将其添加到源代码管理中)

注意:您应该在文件中输入 nuget.org 的 feed url 和您的私人 feed Nuget.Config

Nuget.Config2.在 azure devops 存储库中配置文件的路径Path to Nuget.config

3.如果您没有私人订阅源,请创建新的服务连接:

在此输入图像描述

4.选择basic Authentication并输入用户名和密码,并为服务连接命名,然后保存。

在此输入图像描述

现在,Azure Devops 服务可以在恢复项目的 nuget 包时访问您的私有源。希望能帮助到你 :)