Search code examples
tfshttp-proxynuget-package-restore

NuGet can't restore packages behind the proxy


So we've been really struggling with the issue of NuGet unable to restore packages when behind a corporate proxy. I will go over our setup.

Hardware / Software:

WinServer 2012 R2 joined to a domain and behind a corporate proxy

TFS 2017 with Update2

NuGet Restore Error

Basically all we are doing is trying to setup a build automation for our environment. Right now we are just experimenting with it and have created a basic Visual Studio App with a NuGet Restore step in the build definition.

Sady the NuGet Restore step fails with the following error. Relevant files from the log are below:

2017-08-11T13:49:41.7282874Z     Unable to find version '1.5.2' of package 'WebGrease'.
2017-08-11T13:49:41.7282874Z       https://api.nuget.org/v3/index.json: Unable to load the service index for source https://api.nuget.org/v3/index.json.
2017-08-11T13:49:41.7282874Z       An error occurred while sending the request.
2017-08-11T13:49:41.7282874Z       Unable to connect to the remote server
2017-08-11T13:49:41.7282874Z       A socket operation was attempted to an unreachable network [2606:2800:11f:17a5:191a:18d5:537:22f9]:443
2017-08-11T13:49:41.7282874Z 
2017-08-11T13:49:41.7282874Z NuGet Config files used:
2017-08-11T13:49:41.7282874Z     C:\Windows\ServiceProfiles\NetworkService\AppData\Roaming\NuGet\NuGet.Config
2017-08-11T13:49:41.7282874Z 
2017-08-11T13:49:41.7282874Z Feeds used:
2017-08-11T13:49:41.7282874Z     https://api.nuget.org/v3/index.json
2017-08-11T13:49:41.8064377Z ##[error]Error: C:\agent\_work\_tasks\NuGetInstaller_333b11bd-d341-40d9-afcf-b32d5ce6f23b\0.2.31\node_modules\nuget-task-common\NuGet\4.0.0\NuGet.exe failed with return code: 1
2017-08-11T13:49:41.8064377Z ##[error]Packages failed to install
2017-08-11T13:49:41.8064377Z ##[section]Finishing: NuGet restore **\*.sln

What we tried

From the log, it is evident that the NuGet.config file is located here:

C:\Windows\ServiceProfiles\NetworkService\AppData\Roaming\NuGet\NuGet.config

When we modify the NuGet.config file to include the proxy settings like so:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
  </packageSources>
  <config>
        <add key="http_proxy" value="http://MY_USER_NAME:MY_PASSWORD@OUR_DOMAIN.com" />
  </config>
</configuration>

Then the error becomes different:

 Unable to find version '1.5.2' of package 'WebGrease'.
      https://api.nuget.org/v3/index.json: Unable to load the service index for source https://api.nuget.org/v3/index.json.
      An error occurred while sending the request.
      The remote server returned an error: (400) Bad Request.

Everything works fine if the server is connected to the internet without going through the proxy.

Did anyone else experience the same issues? Does our proxy configuration look correct? Any help would be really appreciated.

Thank you.


Solution

  • The solution is that you have to configure the VSTS Build Agent to run under a domain user account.