C# 代理背后的 NuGet
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9232160/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NuGet behind a proxy
提问by Ricardo
I figure out that NuGet allows proxy settings configuration since 1.4 version. But, I can't find any command line example.
我发现 NuGet 从 1.4 版本开始就允许代理设置配置。但是,我找不到任何命令行示例。
I'm trying to run some build and NuGet can't connect.
我正在尝试运行一些构建,但 NuGet 无法连接。
How do I configure the proxy settings on the command line?
如何在命令行上配置代理设置?
回答by David McLean
I could be wrong but I thought it used IE's proxy settings.
我可能是错的,但我认为它使用了 IE 的代理设置。
If it sees that you need to login it opens a dialog and asks you to do so (login that is).
如果它看到您需要登录,它会打开一个对话框并要求您这样做(即登录)。
Please see the description of this here -> http://docs.nuget.org/docs/release-notes/nuget-1.5
请在此处查看此说明-> http://docs.nuget.org/docs/release-notes/nuget-1.5
回答by Tx3
Maybe you could try this to your devenv.exe.config
也许你可以试试这个到你的devenv.exe.config
<system.net>
<defaultProxy useDefaultCredentials="true" enabled="true">
<proxy proxyaddress="http://proxyaddress" />
</defaultProxy>
<settings>
<servicePointManager expect100Continue="false" />
<ipv6 enabled="true"/>
</settings>
</system.net>
I found it from the NuGet Issue tracker
我从NuGet 问题跟踪器中找到了它
There are also other valuable comments about NuGet + network issues.
还有其他关于 NuGet + 网络问题的宝贵意见。
回答by Ivan Danilov
回答by arcain
Here's what I did to get this working with my corporate proxy that uses NTLM authentication. I downloaded NuGet.exeand then ran the following commands (which I found in the comments to this discussionon CodePlex):
这是我为使用我的使用 NTLM 身份验证的公司代理所做的工作。我下载了NuGet.exe,然后运行了以下命令(我在 CodePlex 上的讨论的评论中找到了这些命令):
nuget.exe config -set http_proxy=http://my.proxy.address:port
nuget.exe config -set http_proxy.user=mydomain\myUserName
nuget.exe config -set http_proxy.password=mySuperSecretPassword
This put the following in my NuGet.configlocated at %appdata%\NuGet(which maps to C:\Users\myUserName\AppData\Roamingon my Windows 7 machine):
这将以下内容放在我的NuGet.config位置%appdata%\NuGet(在我的 Windows 7 机器上映射到 C:\Users\myUserName\AppData\Roaming):
<configuration>
<!-- stuff -->
<config>
<add key="http_proxy" value="http://my.proxy.address:port" />
<add key="http_proxy.user" value="mydomain\myUserName" />
<add key="http_proxy.password" value="base64encodedHopefullyEncryptedPassword" />
</config>
<!-- stuff -->
</configuration>
Incidentally, this also fixed my issue with NuGet only working the first time I hit the package source in Visual Studio.
顺便说一句,这也解决了我第一次在 Visual Studio 中点击包源时 NuGet 工作的问题。
Note that some people who have tried this approach have reported through the comments that they have been able to omit setting the
http_proxy.passwordkey from the command line, or delete it after-the-fact from the config file, and were still able to have NuGet function across the proxy.
请注意,一些尝试过这种方法的人通过评论报告说他们已经能够
http_proxy.password从命令行省略设置密钥,或者事后从配置文件中删除它,并且仍然能够拥有 NuGet 功能跨代理。
If you find, however, that you mustspecify your password in the NuGet config file, remember that you have to update the stored password in the NuGet config from the command line when you change your network login, if your proxy credentials are also your network credentials.
但是,如果您发现必须在 NuGet 配置文件中指定密码,请记住,如果您的代理凭据也是您的网络,则必须在更改网络登录时从命令行更新 NuGet 配置中存储的密码凭据。
回答by Roman Mahrer
Just in case you are using the https version of nuget (https://www.nuget.org), be aware that you have to set the values with https.
以防万一您使用 https 版本的 nuget ( https://www.nuget.org),请注意您必须使用 https 设置值。
- https_proxy
- https_proxy.user
- https_proxy.password
- https_proxy
- https_proxy.user
- https_proxy.password
回答by mithun_daa
Apart from the suggestions from @arcain I had to add the following Windows Azure Content Delivery Network url to our proxy server's the white-list:
除了来自@arcain 的建议之外,我还必须将以下 Windows Azure 内容交付网络 url 添加到我们代理服务器的白名单中:
.msecnd.net
回答by Aishel M
Another flavor for same "proxy for nuget": alternatively you can set your nuget proxing settings to connect through fiddler. Below cmd will save proxy settings in in default nuget config file for user at %APPDATA%\NuGet\NuGet.Config
相同的“nuget 代理”的另一种风格:或者,您可以将 nuget 代理设置设置为通过fiddler进行连接。下面的 cmd 会将代理设置保存在用户的默认 nuget 配置文件中%APPDATA%\NuGet\NuGet.Config
nuget config -Set HTTP_PROXY=http://127.0.0.1:8888
Whenever you need nuget to reach out the internet, just open Fiddler, asumming you have fiddler listening on default port 8888.
每当您需要 nuget 访问互联网时,只需打开 Fiddler,假设您让 Fiddler 监听默认端口 8888。
This configuration is not sensitive to passwork changes because fiddler will resolve any authentication with up stream proxy for you.
此配置对密码更改不敏感,因为 fiddler 将为您解析任何与上游代理的身份验证。
回答by 8DH
Just a small addition...
只是一个小小的补充...
If it works for you to only supply the http_proxy setting and not username and password I'd recommend putting the proxy settings in a project local nuget.config file and commit it to source control. That way all team members get the same settings.
如果只提供 http_proxy 设置而不是用户名和密码对您有用,我建议将代理设置放在项目本地 nuget.config 文件中并将其提交到源代码管理。这样所有团队成员都会获得相同的设置。
Create an empty .\nuget.config
创建一个空的 .\nuget.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
</configuration>
Then:
然后:
nuget config -Set http_proxy="http://myproxy.example.com:8080" -ConfigFile .\Nuget.Config
And finally commit your new project local Nuget.config file.
最后提交您的新项目本地 Nuget.config 文件。
回答by r590
To anyone using VS2015: I was encountering a "407 Proxy Authentication required" error, which broke my build. After a few hours investigating, it turns out MSBuild wasn't sending credentials when trying to download Nuget as part of the 'DownloadNuGet' target. The solution was to add the following XML to C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe.config inside the <configuration>element:
对于使用 VS2015 的任何人:我遇到了“需要 407 代理身份验证”错误,这破坏了我的构建。经过几个小时的调查,结果发现当尝试下载 Nuget 作为“DownloadNuGet”目标的一部分时,MSBuild 没有发送凭据。解决方案是将以下 XML 添加到 C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe.config<configuration>元素内:
<system.net>
<defaultProxy useDefaultCredentials="true">
</defaultProxy>
</system.net>
回答by Ram
Above Solution by @arcain Plus below steps solved me the issue
以上解决方案由@arcain Plus 以下步骤解决了我的问题
Modifying the "package sources" under Nuget package manger settings to check the checkbox to use the nuget.org settings resolved my issue.
I did also changed to use that(nuget.org) as the first choice of package source
I did uncheck my company package sources to ensure the nuget was always picked up from global sources.
修改 Nuget 包管理器设置下的“包源”以选中复选框以使用 nuget.org 设置解决了我的问题。
我也改为使用 that(nuget.org) 作为包源的首选
我确实取消了我公司的包源以确保 nuget 总是从全球来源中获取。

