在尝试连接到Nuget时,我得到了下面的错误,然后我无法连接:

无法加载源的服务索引 https://api.nuget.org/v3/index.json。 发送请求时发生错误。 无法连接到远程服务器 连接尝试失败,原因是被连接方在一段时间后没有正确响应,或已建立连接 由于连接的主机未能响应68.232.34.200:443而失败

我可以在浏览器上访问https://api.nuget.org/v3/index.json。


当前回答

这也可能由于身份验证问题而发生,因此您可能需要重新对Visual Studio进行身份验证。

在这种情况下,只需在包所在的文件夹中运行以下命令。配置文件的位置(通常是项目的根目录):

dotnet restore --interactive

系统将提示您从浏览器访问配对URL并输入配对代码,例如:

要登录,请使用网络浏览器打开页面https://microsoft.com/devicelogin,并输入代码C2DEJ87H到 身份验证。

这需要.NET CLI,它包含在.NET Core SDK中,可以从https://learn.microsoft.com/en-us/dotnet/core/install/windows安装

其他回答

在我的情况下,我必须在Visual studio Options->NugetPAckageManager->sources中添加源 然后重新启动visual studio命令提示符

禁用防病毒应用程序。 以我为例,AVG阻止我访问nuget.org

设置(PC全局设置)>网络和Internet >代理>自动代理设置>和“自动检测设置”设置为“关闭”。

简单:

关闭VS2019 去c:\ users \you\ appdata \ roam \ nuget 删除文件NuGet。配置 重启VS2019

你可以开始了!

在我的例子中,问题在于我是在旧的Win7虚拟机上构建的。

我从https://github.com/NuGet/NuGetGallery/issues/8176#issuecomment-683923724找到了这个修复:

nuget.org started enforcing the use of TLS 1.2 (and dropped support for TLS 1.1 and 1.0) earlier this year. Windows 7 has TLS 1.2 disabled by default (check the DisabledByDefault value under HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client in your registry). To enable the support, please make sure you have an update (*) installed and switch the support on: 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

(*)更新指的是Microsoft kb3140245: Windows 7更新(KB3140245)

我安装了更新,重新启动(按照更新的要求),添加了那些注册表项,然后Nuget就可以正常工作了。