FBryant87
FBryant87

Reputation: 4605

Nuget restore works in Visual Studio, but not from command line

Within Visual Studio, I configure an Azure DevOps nuget feed which requires authentication. Somehow, this automatically works in VS, and I can access and retrieve the packages from the feed as usual.

But as soon as I run a nuget restore from the command line, I'm asked for credentials. Why is this?

How is Visual Studio automatically detecting the credentials to use for the feed, and how can I replicate this on the command line?

This suggestion doesn't seem to work at all, it still asks for credentials:

nuget sources Update -name feed.com -username aaa -password bbb

(I'm using VS2017, for a .NET Framework project)

Upvotes: 1

Views: 1321

Answers (1)

zivkan
zivkan

Reputation: 14991

I'm not 100% sure what NuGet does with the username and password provided on the command line, but my guess would be HTTP Basic authentication. However, HTTP Basic is not considered a good practice, so the fewer web applications that use it the better. Azure DevOps rightly doesn't accept it as a form of authentication to their private feeds.

With Azure DevOps, you have two choices. One choice is to create a Personal Access Token and use that. I'm not going to get into why using a token is more secure than HTTP Basic username and password, there's plenty of information on the internet you can easily find with a quick search.

The other option is to use the Microsoft NuGet Credential Provider. Visual Studio has one built-in. I'm not sure about the dotnet cli. But if you're using nuget.exe, you'll need to download their credial provider as described in the linked docs page. If you're investigating for a CI pipeline running on Azure DevOps, as the top of the docs page says, they have the credential provider built into their NuGet tasks.

In any case, sorry to sound like a jerk, but there are quite a few docs and blog posts and other information about using Azure DevOps NuGet feeds and getting credentials working. If you've followed those instructions and still have problems, we might be able to help, but I believe the information you need is already documented and answered by several other Stack Overflow answers.

Upvotes: 3

Related Questions