Thursday, May 17, 2018

Fix Nuget package errors with Visual Studio 2017 Enterprise

If you face problems accessing/installing the nuget packages from Visual Studio 2017 Enterprise edition, please follow the below steps:

  1. Copy the .nuget folder into the solution folder. It should have 3 files: Nuget.Config, Nuget.exe and Nuget.Targets
  2. Edit Nuget.Config as below:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <solution>
    <add key="disableSourceControlIntegration" value="true" />
  </solution> 
  <packageSources> 
       <add key="http_proxy" value="company proxy address" />
       <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" /> 
       <add key="nuget.org" value="https://www.nuget.org/api/v2/" /> 
       <add key="Local" value="local folder\Nuget Packages\" /> 
  </packageSources>
  <packageRestore>
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>
</configuration>
  1. Close and Exit Visual Studio.

Other way to add proxy entry is to run the following command:
nuget.exe config -set http_proxy=http://my.proxy.address:port
In case you are wondering how to get proxy:

  1. Open chrome, go to below URL to see the proxy details: chrome://net-internals/#proxy
  2. Check Proxy tab on left. Run the PAC script in browser URL
  3. It should download one pac file . Open in notepad. Check for something like this:
if ( host == "abc.com" )
      { return "PROXY IP Address:Port"; }

Thats your proxy.

If this doesn't work, try below:
<system.net>
    <defaultProxy useDefaultCredentials="true" enabled="true">
        <proxy proxyaddress="http://your.proxyserver.ip:port"/>
    </defaultProxy>
    <settings>
        <ipv6 enabled="true"/>
        <servicePointManager expect100Continue="false" />
    </settings>
</system.net>