VSTS 无法加载源 401 的服务索引

VSTS unable to load the service index for source 401

我知道关于相同签名的其他帖子。通过他们,我仍然无法解决我的问题。

我的团队使用 VSTS 的构建定义进行持续集成。

此构建定义在最后一个拉取请求之前工作正常。 在 Nuget 恢复期间,我 运行 收到下面的错误消息

2018-06-20T00:37:27.6438127Z System.AggregateException: One or more errors occurred. ---> NuGet.Protocol.Core.Types.FatalProtocolException: Unable to load the service index for source https://microsoft.pkgs.visualstudio.com/_packaging/CBT/nuget/v3/index.json. ---> System.Net.Http.HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).

我在 nuget.config 中确实有 https://microsoft.pkgs.visualstudio.com/_packaging/CBT/nuget/v3/index.json,在失败的 PR[=13] 中 nuget.config 中没有任何变化 =]

我可以使用 VS2017 在我的本地机器上成功地恢复和构建整个解决方案。 PR 中唯一相关的变化是它不再使用 package.config,而是使用 packagereference 来获取 nuget 包。我试图回到使用 package.config,构建仍然会失败并出现相同的错误消息。

提前致谢。

您可以在指定的 nuget.config 文件中使用凭据(PAT 或备用凭据)更新 VSTS 源。

如:

nuget sources update -Name "vstsfeed" -Source https://microsoft.pkgs.visualstudio.com/_packaging/CBT/nuget/v3/index.json -Username "Alternate username" -Password "alternate password" -configfile /path/to/nuget.config

然后您可以提交对 nuget.config 文件的更改并推送到 VSTS 存储库。并再次构建以检查它是否有效。

您可以使用接受的答案中所示的命令 - 此外,您可以将提要添加到位于存储库根目录中的 nuget.config 文件中

Notice, this shows how to add credentials for a custom feed with spaces in the feed name: My Nuget Artifacts

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageRestore>
    <!-- Allow NuGet to download missing packages -->
    <add key="enabled" value="True" />
    <!-- Automatically check for missing packages during build in Visual Studio -->
    <add key="automatic" value="True" />
  </packageRestore>
  <packageSources>
    <add key="NuGet official package source" value="https://api.nuget.org/v3/index.json" />
    <add key="My Nuget Artifacts" value="https://pkgs.dev.azure.com/ConsotoOrg/_packaging/Consoto/nuget/v3/index.json" />
  </packageSources>
  <packageSourceCredentials>
    <My_x0020_NuGet_x0020_Artifacts>
      <add key="Username" value="justme" />
      <add key="ClearTextPassword" value="xyzyoqyvslyfs1t1khru6wd33gebujhpr9moocbujfhv8ukxtxyz" />
    </My_x0020_NuGet_x0020_Artifacts>
  </packageSourceCredentials>
  <activePackageSource>
    <add key="All" value="(Aggregate source)" />
  </activePackageSource>
  <!--
        Used to specify trusted signers to allow during signature verification.
        See: nuget.exe help trusted-signers
    -->
  <trustedSigners>
    <author name="microsoft">
      <certificate fingerprint="3F9001EA83C560D712C24CF213C3D312CB3BFF51EE89435D3430BD06B5D0EECE" hashAlgorithm="SHA256" allowUntrustedRoot="false" />
    </author>
    <repository name="nuget.org" serviceIndex="https://api.nuget.org/v3/index.json">
      <certificate fingerprint="0E5F38F57DC1BCC806D8494F4F90FBCEDD988B46760709CBEEC6F4219AA6157D" hashAlgorithm="SHA256" allowUntrustedRoot="false" />
      <owners>microsoft;aspnet;nuget</owners>
    </repository>
  </trustedSigners>
</configuration>

FWIW - In recent days, I've found I can clear up some NuGet restore errors by removing the trustedSigners section from the config

这不是 OP 的问题所在,但我在此处添加注释,因为我在搜索相同的错误消息时发现了这个问题。

在我们的案例中,我们在 Azure DevOps 中构建了一个 .net 5 应用程序。我们必须使用 NuGet 工具安装程序升级到更新版本的 NuGet。然后使用 .Net Core 任务和 restore 命令恢复工作正常。