How to specify credentials for external nuget feeds in VSTS nuget restore

为君一笑 提交于 2021-01-28 02:17:02

问题


I'm using the built in nuget task in VSTS to do a package restore. Our feed is hosted on an internal Artifactory server, and is referenced as a package source in my nuget.config. I'm then using a nuget service endpoint in VSTS to store the credentials to access that feed.

But when I run the build I get the following in the build log, and every request to the nuget feed results in a 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'.

Is there anything else I need to configure to get the task to pickup the credentials in the service endpoint? If I just put them as packageSourceCredentials in the nuget.config, it all works fine.


回答1:


Since the nuget packages feed is located in internal server, you should use the private build agent which can access the URL http://repo1:8081/artifactory/api/nuget/nuget-repos/Packages.

And there are two options can add the nuget feed credential when you execute NuGet restore task:

Option1: Use nuget service endpoint as you used

You can add Nuget endpoint with Basic Authentication. After enter feed URL, username and password, please also verify the connection before save.

Option2: add credential in your nuget.config file

In your local repo, you can add credentical to your project level nuget.config file as below command:

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

Then your can commit and push (checkin) the change to remote repo, and build without specifying the nuget service endpoint.

Note:

  • Since the packages seems located in nuget-repos/Package, you should use http://repo1:8081/artifactory/api/nuget/nuget-repos/Packages as feed URL (not http://repo1:8081/artifactory/api/nuget/nuget-repos).
  • Except 401 error message, there also has a warning that shows the package Microsoft.AspNet.Razor 3.2.3 not found. So please also check if the package exist in your feed.


来源:https://stackoverflow.com/questions/46794711/how-to-specify-credentials-for-external-nuget-feeds-in-vsts-nuget-restore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!