如何在 VSTS nuget 还原中指定外部 nuget 源的凭据

ssl*_*oan 5 nuget azure-devops azure-pipelines

我正在使用 VSTS 中内置的 nuget 任务来执行包恢复。我们的提要托管在内部 Artifactory 服务器上,并在我的 nuget.config 中作为包源进行引用。然后,我使用 VSTS 中的 nuget 服务端点来存储访问该源的凭据。

NuGet 任务屏幕截图

但是,当我运行构建时,我会在构建日志中看到以下内容,并且对 nuget feed 的每个请求都会导致 401 Unauthorized。

CredentialProvider.TeamBuild: URI Prefixes:
CredentialProvider.TeamBuild:     https://ukipo.visualstudio.com/
CredentialProvider.TeamBuild:     https://ukipo.pkgs.visualstudio.com/
CredentialProvider.TeamBuild: URI: http://repo1:8081/artifactory/api/nuget/nuget-repos
CredentialProvider.TeamBuild: Is retry: False
CredentialProvider.TeamBuild: Matched prefix: 
CredentialProvider.TeamBuild: This provider only handles URIs from the build's Team Project Collection

Unauthorized http://repo1:8081/artifactory/api/nuget/nuget-repos/Packages(Id='Microsoft.AspNet.Razor',Version='3.2.3') 16ms
WARNING: Unable to find version '3.2.3' of package 'Microsoft.AspNet.Razor'.
  http://repo1:8081/artifactory/api/nuget/nuget-repos: The V2 feed at 'http://repo1:8081/artifactory/api/nuget/nuget-repos/Packages(Id='Microsoft.AspNet.Razor',Version='3.2.3')' returned an unexpected status code '401 Unauthorized'.
Run Code Online (Sandbox Code Playgroud)

我还需要配置其他任何内容才能获取在服务端点中获取凭据的任务吗?如果我只是将它们放入packageSourceCredentialsnuget.config 中,一切都会正常工作。

Mar*_*Liu 3

由于 nuget 包源位于内部服务器中,因此您应该使用可以访问 URL http://repo1:8081/artifactory/api/nuget/nuget-repos/Packages 的私有构建代理

当您执行 NuGet 恢复任务时,有两个选项可以添加 nuget feed 凭据:

选项1:使用您所使用的nuget服务端点

您可以使用基本身份验证添加 Nuget 端点。输入 feed URL、用户名和密码后,请在保存前验证连接。

在此输入图像描述

nuget.config选项2:在您的文件中添加凭据

在本地存储库中,您可以将凭据添加到项目级别nuget.config文件中,如下命令:

nuget sources add -name "nuget-repos" -source "http://repo1:8081/artifactory/api/nuget/nuget-repos/Packages" -username "username" -password "password" -ConfigFile path\to\project\.nuget\nuget.config
Run Code Online (Sandbox Code Playgroud)

然后,您可以将更改提交并推送(签入)到远程存储库,并在不指定 nuget 服务端点的情况下进行构建。

笔记: