简体   繁体   English

NuGet 在代理后面

[英]NuGet behind a proxy

I figure out that NuGet allows proxy settings configuration since 1.4 version (June 2011) .我发现 NuGet 自1.4 版本 (2011 年 6 月)起允许代理设置配置。 But, I can't find any command line example.但是,我找不到任何命令行示例。

I'm trying to run some build and NuGet can't connect.我正在尝试运行一些构建,但 NuGet 无法连接。

How do I configure the proxy settings on the command line?如何在命令行上配置代理设置?

Here's what I did to get this working with my corporate proxy that uses NTLM authentication.这是我为使用我的使用 NTLM 身份验证的公司代理所做的工作。 I downloaded NuGet.exe and then ran the following commands (which I found in the comments to this discussion on CodePlex):我下载了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.config located at %appdata%\\NuGet (which maps to C:\\Users\\myUserName\\AppData\\Roaming on my Windows 7 machine):这将以下内容NuGet.config位于%appdata%\\NuGet NuGet.config (它映射到我的 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.password key 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 must specify 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 配置中存储的密码凭据

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 + 网络问题的宝贵意见。

以防万一您使用NuGet的 HTTPS 版本,请注意您必须使用 HTTPS 设置值。

  • https_proxy
  • https_proxy.user
  • https_proxy.password

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

Another flavor for same "proxy for nuget": alternatively you can set your nuget proxing settings to connect through fiddler .相同的“nuget 代理”的另一种风格:或者,您可以将 nuget 代理设置设置为通过fiddler进行连接。 Below cmd will save proxy settings in in default nuget config file for user at %APPDATA%\\NuGet\\NuGet.Config下面的 cmd 会将代理设置保存在%APPDATA%\\NuGet\\NuGet.Config用户的默认 nuget 配置文件中

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 将为您解析任何与上游代理的身份验证。

To anyone using VS2015: I was encountering a "407 Proxy Authentication required" error, which broke my build.对于使用 VS2015 的任何人:我遇到了“需要 407 代理身份验证”错误,这破坏了我的构建。 After a few hours investigating, it turns out MSBuild wasn't sending credentials when trying to download Nuget as part of the 'DownloadNuGet' target.经过几个小时的调查,结果发现当尝试下载 Nuget 作为“DownloadNuGet”目标的一部分时,MSBuild 没有发送凭据。 The solution was to add the following XML to C:\\Program Files (x86)\\MSBuild\\14.0\\Bin\\MSBuild.exe.config inside the <configuration> element:解决方案是将以下 XML 添加到 C:\\Program Files (x86)\\MSBuild\\14.0\\Bin\\MSBuild.exe.config <configuration>元素内:

<system.net>
            <defaultProxy useDefaultCredentials="true">
            </defaultProxy>
</system.net>

The solution for me was to include我的解决方案是包括

<configuration>
  <config>
    <add key="http_proxy" value="http://<IP>:<Port>" />
    <add key="http_proxy.user" value="<user>" />
    <add key="http_proxy.password" value="<password>" />
  </config>
</configuration>

In the nuget.config file.nuget.config文件中。

Maybe this helps someone else.也许这对其他人有帮助。 For me the solution was to open NuGet settings on Visual Studio (2015/2017) and add a new feed URL: http://www.nuget.org/api/v2/ .对我来说,解决方案是在 Visual Studio (2015/2017) 上打开 NuGet 设置并添加一个新的提要 URL: http : //www.nuget.org/api/v2/

I didn't have to change any proxy related settings.我不必更改任何与代理相关的设置。

On Windows Server 2016 Standard, which is what I develop on, I just had to open the Credential Manager Control Panel and clear out the cached proxy settings for Visual Studio which were no longer valid and then restart Visual Studio.在我开发的 Windows Server 2016 Standard 上,我只需要打开凭据管理器控制面板并清除不再有效的 Visual Studio 缓存代理设置,然后重新启动 Visual Studio。 The next time I opened the Nuget Package Manager I was prompted for proxy credentials, which got me working again.下次我打开 Nuget 包管理器时,系统提示我输入代理凭据,这让我再次工作。

See: https://support.microsoft.com/en-us/help/4026814/windows-accessing-credential-manager请参阅: https : //support.microsoft.com/en-us/help/4026814/windows-accessing-credential-manager

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.如果只提供 http_proxy 设置而不是用户名和密码对您有用,我建议将代理设置放在项目本地 nuget.config 文件中并将其提交到源代码管理。 That way all team members get the same settings.这样,所有团队成员都会获得相同的设置。

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 文件。

Try this .试试这个 Basically, connection could fail if your system doesn't trust nuget certificate.基本上,如果您的系统不信任 nuget 证书,连接可能会失败。

除了来自@arcain 的建议之外,我还必须将以下 Windows Azure 内容交付网络 url 添加到我们代理服务器的白名单中:

.msecnd.net

Above Solution by @arcain Plus below steps solved me the issue以上解决方案由@arcain Plus 以下步骤解决了我的问题

  1. Modifying the "package sources" under Nuget package manger settings to check the checkbox to use the nuget.org settings resolved my issue.修改 Nuget 包管理器设置下的“包源”以选中复选框以使用 nuget.org 设置解决了我的问题。

  2. I did also changed to use that(nuget.org) as the first choice of package source我也改用那个(nuget.org)作为包源的首选
    I did uncheck my company package sources to ensure the nuget was always picked up from global sources.我确实取消了我公司的包裹来源,以确保 nuget 总是从全球来源中提取。

As a late answer, for me nothing worked here.作为一个迟到的答案,对我来说这里没有任何效果。 I guess this might depend on your company proxies or how the nuget is implemented but for some reason I had the following environment variables set: http_proxy and https_proxy .我想这可能取决于您公司的代理或nuget的实现方式,但出于某种原因,我设置了以下环境变量: http_proxyhttps_proxy After I removed them, nuget started working correctly.删除它们后, nuget开始正常工作。

Hello for me going into你好,我要进入

%appdata%/Roaming/Nuget/NuGet.Config and removing every line except for the package sources. %appdata%/Roaming/Nuget/NuGet.Config 并删除除包源之外的每一行。 Which should give something like this哪个应该给出这样的东西

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
  </packageSources>
</configuration>

Full path should be C:\\Users<username>\\AppData\\Roaming\\NuGet\\NuGet.Config完整路径应为 C:\\Users<username>\\AppData\\Roaming\\NuGet\\NuGet.Config

Basically there was a proxy set, i don't how and why it was set but it was there and i couldn't ping it either.基本上有一个代理集,我不知道它是如何以及为什么设置的,但它在那里,我也无法ping通它。

It's correlated, but not the same cenario here, but I would like to document for those on Linux.它是相关的,但不是相同的场景,但我想为 Linux 上的人记录。

I'm on Fedora 35 using VsCode and dotnet sdk 6 installed我在 Fedora 35 上使用 VsCode 和 dotnet sdk 6 安装

To use dotnet add package behind proxy I have to use this format of command:要在代理后面使用dotnet add package我必须使用以下命令格式:

export http_proxy=http://[user]:[pass]@[server]:[port] && dotnet add package <package>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM