NuGet package recovery Unable to request credentials using custom feed

I have included NuGet Package recovery in my solution. I am using nuget.exe version 2.0.30828.5. For packages that are in a regular public channel, 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 fine.

However, when we try to use NPR for the package in our custom feed (the user feed has basic authentication), we get the following:

EXEC : warning : Unable to prompt for credentials. Consult NuGet 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 and also decompile nuget.exe to find the line β€œCannot request credentials. Refer to the NuGet help documentation on how to specify credentials.” I see this there, but honestly, I can’t determine who uses this error message.

When we add a package (either from the NuGet UI or from the package manager console), it asks for credentials and works fine. This is a problem only when restoring packages.

I tried to execute 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 for a custom NuGet channel using Basic auth to restore a NuGet package?

UPDATE 9/18/2012

I have an update on this issue. I noticed that when I ran the nuget.exe Update Update ... command, it added a section to the NuGet.config file, which was in the local .nuget folder for my solution. Then I ran procmon.exe while starting the build, noticing that this file was not being viewed! Instead, he searched for the NuGet.config file in the directory "C: \ Users {username} \ AppData \ Roaming \ NuGet". Then I copied / pasted the section from the local NuGet.config file to the NuGet.config file in the \ AppData \ Roaming \ NuGet directory and it works!

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

+6
source share
1 answer

It works for me now. This is what I did to make it work. First, the command appears:

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

This is the right way. The caveat is that when you run the Update nuget.exe source command, nuget.exe will look for the NuGet.config file in the same directory as nuget.exe, if it exists. IF , he will save the changes there. If it does NOT exist, it will save the changes to the NuGet.config file located in the% AppData% \ NuGet directory.

An additional caveat is that when package recovery is performed as part of the assembly, it only looks at the NuGet.config file in the% AppData% \ NuGet directory and ignores the NuGet.config file, which is located in the same directory of the nuget.exe executable file (I do not sure this is a mistake or intentional).

So, you must run this command using the nuget.exe file, which is located in a directory that does not have the NuGet.config file, to ensure that the changes are saved in the correct NuGet.config file in% AppData% \ NuGet directory.

+6
source

Source: https://habr.com/ru/post/925611/


All Articles