MSBuild 还原提供 "The request was aborted: Could not create SSL/TLS secure channel."

MSBuild Restore gives "The request was aborted: Could not create SSL/TLS secure channel."

在我的构建服务器上,我使用 MSBuild 恢复任务在构建之前恢复 Nuget 包,但我收到错误:

Unable to load the service index for source https://api.nuget.org/v3/index.json.

An error occurred while sending the request.

The request was aborted: Could not create SSL/TLS secure channel.

当我调用 Nuget.exe 时它起作用了。

MSBuild 版本 = "16.8.2+25e4d540b" 服务器很旧,是Windows 2008 R2 SP1.

我试图检查 TLS 1.2 是否有问题,所以我 运行 一个小程序来测试协议。我从这里得到代码: https://gist.github.com/zivkan/5291f507c8c5724d41a18357b7afcd30

主题: https://developercommunity.visualstudio.com/content/problem/1096460/nuget-not-working-again-could-not-create-ssltls-se.html

结果是:

None worked

Ssl2 failed

Ssl3 failed

Tls failed

Default failed

Tls11 failed

Tls12 worked

Tls13 failed

根据评论应该可以吧

接下来我应该怎么做才能让 MSBuild 恢复正常工作?

试试这个:

建议

1) 因为您只安装了 TLS1.2 而不是 TLS1.3。尝试将其打开。 运行 Developer Powershell for VS2019 as Administrator:

下的这些命令
reg add "HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client" /v DisabledByDefault /t REG_DWORD /d 0 /f /reg:32
reg add "HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client" /v DisabledByDefault /t REG_DWORD /d 0 /f /reg:64
reg add "HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client" /v Enabled /t REG_DWORD /d 1 /f /reg:32
reg add "HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client" /v Enabled /t REG_DWORD /d 1 /f /reg:64

2) 如果第一步不起作用,试试这些:

New-Item 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Server' -Force | Out-Null
    
New-ItemProperty -path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Server' -name 'Enabled' -value '0' -PropertyType 'DWord' -Force | Out-Null
    
New-ItemProperty -path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Server' -name 'DisabledByDefault' -value 1 -PropertyType 'DWord' -Force | Out-Null
    
New-Item 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Client' -Force | Out-Null
    
New-ItemProperty -path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Client' -name 'Enabled' -value '0' -PropertyType 'DWord' -Force | Out-Null
    
New-ItemProperty -path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Client' -name 'DisabledByDefault' -value 1 -PropertyType 'DWord' -Force | Out-Null
Write-Host 'TLS 1.3 has been disabled.'

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