NuGet to work behind a proxy

In this article, I am going to explain – the Configuration steps for NuGet to work behind a proxy.

What is NPM?

NuGet is the package manager for the Microsoft development platform including .NET.
When you use NuGet to install a package, it copies the library files to your solution and automatically updates your project (add references, change config files, etc.). If you remove a package, NuGet reverses whatever changes it made so that no clutter is left.

If you work behind a proxy, when you try to add a NuGet package to your Visual Studio project, probably this message will compare in the output tab:

error: Failed to retrieve information from remote source …
error: Response status code does not indicate success: 407 (Proxy Authentication Required).

It means that NuGet is trying to download the package, but the proxy is blocking.

Open the file C:\Users\[YOUR_USER_NAME]\AppData\Roaming\NuGet\NuGet.Config and add inside the <\configuration> tag the following:

The file location can also be found from the properties of the Nuget location from Visual Studio as in below figure:

Note: Replacing,
[YOUR_USER_NAME] with your Windows account name
[YOUR_PROXY_ADDRESS] with the address of the proxy
[YOUR_PROXY_PORT] with the port of the proxy

Open Visual Studio and NuGet should automatically restore the packages.

Leave a Reply

Your email address will not be published. Required fields are marked *