Visual Studio 2019更新中断发布错误的TLS版本

问题描述

短版

如何更改用于获取依赖项的Visual Studio 2019的认TLS版本?

长版

从Visual Studio 2019 v16.7.1开始(最新的v16.7.2不能解决此问题),我似乎无法发布任何dotnet核心项目。发布操作始终会崩溃,并显示以下消息:

Publish has encountered an error.
Publish has encountered an error. We were unable to determine the cause of the error.
Check the output log for more details.

看一下输出窗口:

error message

可以看出,VS似乎无法建立与nuget的TLS连接。 使用Wireshark在发布时进行监视的进一步调查显示

wireshark failing

可以清楚地看到,由于TLS版本不正确,导致连接失败。 Visual Studio似乎使用了TLSv1,但nuget api不支持。我们还可以看到VS重试了几次,因此有大量数据包。

使用我的网络浏览器手动连接到https://api.nuget.org/v3/index.json表示nuget.org实际上使用了TLSv1.2

wireshark success

所以我的问题是:如何告诉Visual Studio使用TLSv1.2而不是TLSv1连接到nuget.org?还是有可能吗?是否有Windows注册表项?

我还没有尝试过重新安装VS,但如果可能的话,我想避免这样做。

解决方法

如注释中所指出的那样,设置了以下注册表项:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\WinHttp\
      DefaultSecureProtocols = (DWORD): 0xAA0
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Internet Settings\WinHttp\
      DefaultSecureProtocols = (DWORD): 0xAA0

(更多文档herehere) 结合取消选中Windows 7控制面板中Use TLS 1.0-> Internet Options下的Advanced选项就可以解决问题。