【问题标题】:Dotnet build in Azure DevOps with private package suorce cannot restore from private nuget feed带有私有包源的 Azure DevOps 中的 Dotnet 构建无法从私有 nuget 源恢复
【发布时间】:2020-01-11 04:39:39
【问题描述】:

我们的项目引用 Azure DevOps 中私有项目源中的包。在 Azure DevOps 中构建项目时,dotnet restore 可以正常完成,但 dotnet build 也尝试恢复包并失败

Unable to load the service index for source https://myazdevops.pkgs.visualstudio.com/_packaging/OurPackages/nuget/v3/index.json

解决方法是将--no-restore 添加到dotnet builddotnet publish 任务中。

有没有什么方法可以让构建和发布在没有参数的情况下开始工作?

【问题讨论】:

    标签: .net-core azure-devops nuget azure-pipelines azure-artifacts


    【解决方案1】:

    我认为您的解决方法是解决方案,在official docs 中写道:

    从 .NET Core 2.0 SDK 开始,dotnet restore 在以下情况下隐式运行 你运行 dotnet build。如果要禁用隐式还原时 运行 build 命令,您可以传递 --no-restore 选项。

    除非添加--no-restore,否则无法禁用此行为。

    另见this问答。

    【讨论】:

    • 但是为什么 dotnet build 不能像 dotnet restore 那样针对 nuget 存储进行身份验证呢?
    • @MathiasR 我不知道:/ 正是我提供的问题中的问题。也许微软的人会提供帮助。
    • 根据下面的答案“...dotnet build 命令。这是一个编译命令,所以我们没有在任务中制作脚本来设置 authinfo”所以这些参数似乎是最简单的方法去
    【解决方案2】:

    我们的内部 NuGet 提要也有类似的问题。 我通过在包含 NuGet.org 和我们内部 NuGet 存储库的存储库中添加 nuget.config 文件来解决它。

    <configuration>
      <packageSources>
        <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
        <add key="internal" value="URL_TO_INTERNAL_FEED" />
      </packageSources>
    </configuration>
    

    然后只需在还原步骤中指定 NuGet.config 的路径 到此文件。

    希望它会有所帮助。

    【讨论】:

    • 我们实际上是这样做的,但是我们得到了 401 Access denied。似乎 dotnet restore 是唯一可以对 nuget repo 进行身份验证的命令。
    • 现在我检查了,我还在构建步骤中添加了 --no-restore。我还添加了 --no-build 到 Publish 步骤,因为它已经构建了。如果你能忍受它......
    【解决方案3】:

    我们已经在 Github 上开放了源代码,您可以参考dotnet build 命令的代码。这是一个编译命令,所以我们没有在任务中制作脚本来额外设置 authinfo。此外,如您所知,dotnet restore隐式运行,而dotnet build 仅在 .net core 2.0 之后运行。事实上,如果你在dotnet build 之前运行过dotnet restore,那么这个隐式运行的dotnet restore 并不是必须的部分。这就是为什么我们提供了workaround - 添加--no-restore - 来避免这个隐式命令。

    这是一个非常方便的方法,可以让你的编译过程非常简洁。但是如果你仍然不想要这个参数,你需要做另一个配置工作来授权凭据。

    配置Azure Artifacts Credential Provider,然后使用VSS_NUGET_EXTERNAL_FEED_ENDPOINTS environment variable 传递凭据。 VSS_NUGET_EXTERNAL_FEED_ENDPOINTS 包含您需要使用 JSON 格式进行身份验证的任何提要的端点凭据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多