Search code examples
nugetconnectionrestore

NuGet.exe from command line gives "existing connection was forcibly closed by the remote host" error


I'm having problems calling NuGet.exe from the command line:

nuget.exe restore solution.sln

On my local machine, this runs without issue from the command line. On the build server, I immediately see the below error:

An existing connection was forcibly closed by the remote host

For background I'm in the process of setting up Jenkins on our build server for our .NET Framework applications.

This error occurs regardless of whether I have Jenkins run the command or I spin up a CMD window (Administrator or otherwise) and run it myself. Even the -Verbosity detailed flag comes up with nothing.

Oddly, when doing a restore against the solution within Visual Studio 2017, it works fine.

Has anyone come across this before or have any ideas?


Solution

  • So this turned out to be a problem with TLS. Having looked up a lot of articles and knowing some ongoing issues with TLS in various places I found this article: Deprecating TLS 1.0 and 1.1 on NuGet.org

    I applied the registry changes mentioned there (as below) and suddenly I got beyond this error

    reg add HKLM\SOFTWARE\Microsoft\.NETFramework\v4.0.30319 /v SystemDefaultTlsVersions /t REG_DWORD /d 1 /f /reg:64
    reg add HKLM\SOFTWARE\Microsoft\.NETFramework\v4.0.30319 /v SystemDefaultTlsVersions /t REG_DWORD /d 1 /f /reg:32