问题
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