【问题标题】:Use licensed NuGet packages in Azure DevOps在 Azure DevOps 中使用许可的 NuGet 包
【发布时间】:2020-03-12 13:30:14
【问题描述】:

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

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

经过研究,尝试了2个选项:

选项 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

我假设它在这两种情况下都会失败,因为临时 nuget.config 文件是空白的。选项 2 之后,配置文件被删除,所以我看不到里面的实际内容。

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

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

编辑答案: Nuget 还原任务 nuget.config 路径为空白,因为我希望自动生成一个与答案内容相似的新任务。 我使用 2 个提要在项目的源代码中添加了一个 Nuget.config,它工作正常。

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

【问题讨论】:

    标签: xamarin.forms azure-devops nuget-package nuget-package-restore


    【解决方案1】:

    请告知我如何将私有包导入 Devops?

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

    对于nuget restore任务,如果我们在feeds to use中选择Feeds in my Nuget.config,我们可以在那里配置Credentials for feeds outside this organization/collection。这就是我们需要的私人订阅源。

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

    按照以下步骤:

    1.在 azure devops repos 中创建一个简单的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>
    

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

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

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

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

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

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

    【讨论】:

      猜你喜欢
      • 2021-08-18
      • 1970-01-01
      • 2019-03-26
      • 2021-04-23
      • 2019-03-14
      • 2019-03-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多