TFS Build Error on NuGet Restore Task ECONNREFUSED


I’m trying to add third new agent to default pool and get an error message on NuGet restore task during testing. The error is “##[error]connect ECONNREFUSED”. What did I do wrong?

2019-06-23T16:12:22.1309391Z ##[section]Starting: NuGet restore
2019-06-23T16:12:22.1465660Z ==============================================================================
2019-06-23T16:12:22.1465660Z Task         : NuGet Restore
2019-06-23T16:12:22.1465660Z Description  : Restores NuGet packages in preparation for a Visual Studio Build step.
2019-06-23T16:12:22.1465660Z Version      : 1.0.1
2019-06-23T16:12:22.1465660Z Author       : Microsoft Corporation
2019-06-23T16:12:22.1465660Z Help         : [More Information](
2019-06-23T16:12:22.1465660Z ==============================================================================
2019-06-23T16:12:23.1623101Z [command]C:\Windows\system32\ 65001
2019-06-23T16:12:23.1623101Z Active code page: 65001
2019-06-23T16:12:24.2466118Z ##[error]connect ECONNREFUSED
2019-06-23T16:12:24.2466118Z ##[section]Finishing: NuGet restore


TFS 2019, Visual Studio 2019, Build Server Agents Version 2.122.1 with Proxy, Build Definition with NuGet Restore Version 1.0.1


Most likely the problem is with connection to outside world. But in this case, it was because it’s missing NuGet.exe file under agent folder \_work\_tool\NuGet\4.0.0\x64\nuget.exe. To make sure you have this file, please check under your TFS Agent folder under _work\_tool\NuGet\4.0.0\x64. Please follow below instructions to check if web proxy setup correctly.

Step-by-step instructions:-

  1. Open File Explorer and browse to where you install TFS Agent
  2. First locate a proxy file named: .proxy (you may need to show hidden file to see it)
  3. Open .proxy file with Notepad and make sure the web proxy gateway name is correct with http/https prefix and port number
  4. Second, check \externals\vstshost\LegacyVSTSPowerShellHost.exe.config file for web proxy settings
  5. Open LegacyVSTSPowerShellHost.exe.config and check if you have defaultProxy attribute under section
        <defaultProxy useDefaultCredentials="true">
          <proxy proxyaddress="" bypassonlocal="true" />
  6. Third, check if you have nuget.exe install under agent folder \_work\_tool\NuGet\4.0.0\x64\
  7. Four (optional), sync \_work\_tasks folder with other agent build server so all build servers have same packages installed
  8. Restart the VSTS Agent service and try to build again


To make sure build server is using proxy to connect to external source, check with firewall log.


Create Build Definition

Leave a Reply