Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NuGet Package Restore Unable to prompt for credentials with custom feed

Tags:

nuget

I have enabled NuGet Package Restore in my solution. I am using nuget.exe version 2.0.30828.5. For packages that are in the normal public feed, NuGet Package Restore works fine. That is, if there is nothing in the "Packages" directory and my local NuGet cache (C:\Users\{username}\AppData\Local\NuGet\Cache) is clear, NPR works perfectly.

However, when we are trying to use NPR for a package in our custom feed (custom feed has Basic authentication) we get this:

EXEC : warning : Unable to prompt for credentials. Consult NuGet's help documentation for ways to specify credentials.
c:\<localpath>\.nuget\nuget.targets(80,9): error : Unable to find version '2.0.1.0' of package '<packageName>'.
c:\<localpath>\.nuget\nuget.targets(80,9): error MSB3073: The command ""c:\<localpath>\.nuget\nuget.exe" install "c:\<localpath>\packages.config" -source ""  -RequireConsent -o "c:\<localpath>\packages"" exited with code 1.

When I look at the NuGet code as well as decompiling nuget.exe to find the string "Unable to prompt for credentials. Consult NuGet's help documentation for ways to specify credentials" I see it there, but frankly, I am unable to determine who is utilizing that error message.

When we add the package (either from the NuGet UI or the Package Manager Console), it prompts for credentials and works fine. This is only a problem on Package Restore.

I tried running this command:

NuGet.exe source Update -Name {feedname} -UserName {myusername} -Password {mypassword}

but gets the same result.

Does anyone know how I can specify credentials to a custom NuGet feed using Basic auth for NuGet Package Restore?

UPDATE 9/18/2012

I have an update on the issue. I observed that when I ran the nuget.exe source Update... command, it added the section to the NuGet.config file that was in the .nuget folder local to my solution. I then ran procmon.exe while running the build a noticed this file was not being looked at! Instead it was looking for the NuGet.config file in the "C:\Users{username}\AppData\Roaming\NuGet" directory. I then copy/pasted the section from the local NuGet.config file into the NuGet.config file in the \AppData\Roaming\NuGet directory, and it worked!

So...the question is, what is the correct best practice for this process?

like image 391
Steve Michelotti Avatar asked Sep 17 '12 21:09

Steve Michelotti


1 Answers

I have this working now. This is what I did to get to get it to work. First, it appears the command:

NuGet.exe source Update -Name {feedname} -UserName {myusername} -Password {mypassword}

IS the right way to go about it. The caveat is that, when your run the "nuget.exe source Update" command, nuget.exe will look for a NuGet.config file in the same directory as the nuget.exe being executed if it exists. IF it exists, it will store the changes there. If it does NOT exist, it will store the changes in the NuGet.config file located in the %AppData%\NuGet directory.

The additional caveat is that, when Package Restore gets executed as part of the build, it only looks at the NuGet.config file in the %AppData%\NuGet directory and ignores the NuGet.config file that is in the same directory of the nuget.exe being executed (I'm unsure if this is a bug or intentional).

So, you should run this command using a nuget.exe that is in a directory that does not have a NuGet.config file in it to ensure the changes get stored in the correct NuGet.config file in the %AppData%\NuGet directory.

like image 139
Steve Michelotti Avatar answered Oct 11 '22 06:10

Steve Michelotti