NuGet behind a proxy
Asked Answered
F

16

134

I figure out that NuGet allows proxy settings configuration since 1.4 version (June 2011). But, I can't find any command line example.

I'm trying to run some build and NuGet can't connect.

How do I configure the proxy settings on the command line?

Fact answered 10/2, 2012 at 17:34 Comment(3)
For the benefit of other users encountering proxy issues: You'll know it could be the proxy if NuGet displays the message: "The remote name could not be resolved: 'nuget.org'"Niigata
Be careful to check the http_proxy and https_proxy environment variables as well as your system proxy settingsMartinic
There's an issue for it now on github: github.com/NuGet/Home/issues/458Lotion
D
255

Here's what I did to get this working with my corporate proxy that uses NTLM authentication. I downloaded NuGet.exe and then ran the following commands (which I found in the comments to this discussion on 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):

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

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.

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.

Deaf answered 17/3, 2013 at 17:34 Comment(11)
The NuGet command-line did not add the entries to my NuGet.config file, but once I manually edited the file, it worked great.Niigata
In my case, I omitted the http_proxy.password key completely and it seemed to be happy to pass through my authenticated AD credentials. This saves the need to change the password frequently.Pinkney
Warning Be careful when you use the configuration suggested by arcain. Make sure you change the password in the config file when you change your Windows password. My Windows account was randomly locked out after changing the password as per the company policy. It took me few hours to figure out that its this config entry causing this whole trouble. The best option is to simply remove the http_proxy.password key as suggested by @Sir CrispalotShylashylock
Try what Sir Crispalot mentioned and remove the http_proxy.password key. That has worked for some people and allowed them to avoid having to change the password in the NuGet config file.Deaf
Another victory here -- using these settings and omitting the password key worked for me behind my corporate proxy with NTLM authentication.Himelman
It worked for me without password as mentioned in the answer. Thanks arcain!Fabulist
@CharlesBurns Link updated. Thanks for the heads up.Deaf
I only ran the first two commands to set the proxy server and user name, and it worked. No password necessary in my case.Byelaw
Not working. I followed the above instructions to setup the Nuget.config since I was behind a company firewall and was facing the proxy issue. But now after adding the proxy in the NugetPackageManager -> PackageSources : nuget.org is getting automatically unchecked. So, I went to the Nuget.config file getting generated in the %appdata%\NuGet, there looks to be this tag <disabledPackageSources> getting generated which has the 'nuget.org'. If I delete the proxy config it won't get generated. Facing a weird issue. Need helpThanks
it works without username and password and you need to restart VS if it was open :)Martres
@Deaf None, of these works for me, tried all of them. On CentOsBussey
G
28

Maybe you could try this to your 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

There are also other valuable comments about NuGet + network issues.

Gauvin answered 28/2, 2012 at 14:13 Comment(3)
but this assumes the devenve.exe (Visual Studio that is) is installed, which should not be in a build serverReconcilable
I had to remove this setting to make it work, so that it follows IE's proxy settings.Exigent
xml <system.net> <defaultProxy useDefaultCredentials="true" enabled="true"> </defaultProxy> <settings> <ipv6 enabled="true"/> </settings> </system.net> Work for me, it used the system proxy settings. Tested on WINDOWS 10Gilgai
A
16

Just in case you are using the HTTPS version of NuGet, be aware that you have to set the values with HTTPS.

  • https_proxy
  • https_proxy.user
  • https_proxy.password
Airdrome answered 22/5, 2014 at 10:19 Comment(3)
The https password is plain text in nuget.config if you follow arcains guide but using httpsTwofaced
This fixed my issue, more details here github.com/NuGet/Home/issues/5980.Translative
So we cannot use 'http' to set proxy address if we are using the https version of nuget?Thanks
T
8

I could be wrong but I thought it used IE's proxy settings.

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

Triparted answered 28/2, 2012 at 14:6 Comment(1)
It does - the issue with this approach arises when your corporation's group policy continually reverts your IE settings to ones that do not work with Nuget, as happens at my place of workUbiety
O
7

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

This configuration is not sensitive to passwork changes because fiddler will resolve any authentication with up stream proxy for you.

Opec answered 30/7, 2015 at 14:0 Comment(0)
H
7

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.

Hypocorism answered 2/3, 2017 at 8:25 Comment(6)
Where can I find this file?Harrie
@MarceloMachado: Here: %AppData%\NuGet\NuGet.configTiti
user's nuget.config location on Windows 10 : %AppData%\Roaming\Nuget\NuGet.configGeorge
You can choose to do ` <add key="http_proxy" value="http://<IP>:<Port>" />` alone without specifying username and password. Remember to restart Visual Studio after that!Adkisson
Restarting VS is important! Also, I think I had issues running as Admin (needed to run as a regular user?)Procrustean
Two other helpful items: you can add "https_proxy" and "no_proxy" values, too. Also, the default NuGet config I found was at "%APPDATA%\NuGet", but you can define nuget.config files in a solution's directory that overrides that default file.Exultation
B
5

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:

<system.net>
            <defaultProxy useDefaultCredentials="true">
            </defaultProxy>
</system.net>
Byway answered 11/4, 2016 at 17:45 Comment(0)
K
4

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

I didn't have to change any proxy related settings.

Kenzi answered 17/3, 2017 at 18:35 Comment(1)
This was the winner for me. Strangely, on my cube PC the original feed URL works but on a lab PC (on a more "secure" network) it failedFregoso
R
2

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. The next time I opened the Nuget Package Manager I was prompted for proxy credentials, which got me working again.

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

Responsiveness answered 8/1, 2020 at 22:17 Comment(1)
Worked for me when getting 407 errors for an internal corporate repo.Bailiwick
D
2

Hello for me going into

%appdata%/Roaming/Nuget/NuGet.Config and removing every line except for the package sources. 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

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.

Darky answered 21/9, 2021 at 10:45 Comment(0)
C
1

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.

Create an empty .\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.

Cloister answered 31/7, 2015 at 11:51 Comment(0)
D
1

It's correlated, but not the same cenario here, but I would like to document for those on Linux.

I'm on Fedora 35 using VsCode and dotnet sdk 6 installed

To use dotnet add package behind proxy I have to use this format of command:

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

Dichlorodifluoromethane answered 1/8, 2022 at 13:54 Comment(0)
D
0

Try this. Basically, connection could fail if your system doesn't trust nuget certificate.

Domett answered 6/12, 2012 at 15:49 Comment(0)
B
0

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:

.msecnd.net
Buyse answered 7/7, 2015 at 21:38 Comment(0)
R
0

Above Solution by @arcain Plus below steps solved me the issue

  1. Modifying the "package sources" under Nuget package manger settings to check the checkbox to use the nuget.org settings resolved my issue.

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

Riehl answered 8/11, 2016 at 3:21 Comment(0)
L
0

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. After I removed them, nuget started working correctly.

Ledoux answered 3/9, 2021 at 11:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.