NuGet 包还原无法使用自定义源提示输入凭据 [英] NuGet Package Restore Unable to prompt for credentials with custom feed

查看:81
本文介绍了NuGet 包还原无法使用自定义源提示输入凭据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的解决方案中启用了 NuGet 包还原.我正在使用 nuget.exe 版本 2.0.30828.5.对于普通公共源中的包,NuGet 包还原工作正常.也就是说,如果Packages"目录中没有任何内容,并且我的本地 NuGet 缓存(C:\Users\{username}\AppData\Local\NuGet\Cache)清晰,则 NPR 工作正常.

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.

但是,当我们尝试将 NPR 用于自定义 Feed(自定义 Feed 具有基本身份验证)中的包时,我们会得到以下信息:

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.

当我查看 NuGet 代码以及反编译 nuget.exe 以找到字符串 无法提示输入凭据.有关指定凭据的方法,请参阅 NuGet 的帮助文档" 我在那里看到它,但坦率地说,我无法确定谁在使用该错误消息.

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.

当我们添加包时(从 NuGet UI 或包管理器控制台),它会提示输入凭据并且工作正常.这只是 Package Restore 的问题.

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.

我尝试运行此命令:

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

但得到相同的结果.

有谁知道我如何使用 NuGet 包还原的基本身份验证为自定义 NuGet 提要指定凭据?

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

更新 9/18/2012

我有关于这个问题的更新.我观察到,当我运行 nuget.exe source Update... 命令时,它将该部分添加到 NuGet.config 文件中,该文件位于我的解决方案本地的 .nuget 文件夹中.然后我在运行构建时运行 procmon.exe 注意到这个文件没有被查看!相反,它正在C:\Users{username}\AppData\Roaming\NuGet"目录中寻找 NuGet.config 文件.然后我将本地 NuGet.config 文件中的部分复制/粘贴到 \AppData\Roaming\NuGet 目录中的 NuGet.config 文件中,并且成功了!

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?

推荐答案

我现在有这个工作.这就是我为使其正常工作所做的工作.首先,出现命令:

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}

是正确的方法.需要注意的是,当您运行nuget.exe 源更新"命令时,nuget.exe 将在与正在执行的 nuget.exe 相同的目录中查找 NuGet.config 文件(如果它存在).如果它存在,它会将更改存储在那里.如果它存在,它会将更改存储在位于 %AppData%\NuGet 目录中的 NuGet.config 文件中.

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.

额外的警告是,当包还原作为构建的一部分执行时,它查看 %AppData%\NuGet 目录中的 NuGet.config 文件并忽略 NuGet.config正在执行的 nuget.exe 所在目录中的文件(我不确定这是错误还是故意的).

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).

因此,您应该使用位于没有 NuGet.config 文件的目录中的 nuget.exe 运行此命令,以确保将更改存储在正确的 NuGet.config 中%AppData%\NuGet 目录中的文件.

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.

这篇关于NuGet 包还原无法使用自定义源提示输入凭据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆