在尝试连接到Nuget时,我得到了下面的错误,然后我无法连接:
无法加载源的服务索引 https://api.nuget.org/v3/index.json。 发送请求时发生错误。 无法连接到远程服务器 连接尝试失败,原因是被连接方在一段时间后没有正确响应,或已建立连接 由于连接的主机未能响应68.232.34.200:443而失败
我可以在浏览器上访问https://api.nuget.org/v3/index.json。
在尝试连接到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安装
其他回答
nuget restore
and
msbuild /t:restore
两者都没有为我工作,因为同样的错误。但
dotnet restore
完美的工作。试试
我在VS2010上使用的是旧版本的Nuget,默认为TLS 1.0 这里可以通过更改.Net框架使用的默认TLS版本来修复,该版本在注册表项中配置
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
FYI
6月15日,NuGet.org将永久移除对TLS 1.0和1.1的支持。请确保您的系统使用TLS 1.2。
您可以参考此链接了解TLS 1.2支持的信息
好吧,我尝试了上面所有的答案,希望我的注册表现在不是软管。但这似乎解决了我的问题:
https://learn.microsoft.com/en-us/answers/questions/959588/visual-studio-2022-won39t-connect-to-nuget.html
添加这个:TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
到this中逗号分隔的字符串:
微软HKLM \ SOFTWARE \政策\ \ SSL加密\ Configuration \ \ 00010002
我希望这能帮助下一个希望在周六早上快速进行有趣的概念验证,然后花3个小时寻找解决方案的人!!
你需要在Nuget中添加代理设置。配置文件。有关详细信息,请参阅此链接:Nuget配置部分和Nuget代理设置。
I had the same error message while scaffolding Identity to my ASP.NET Core MVC project. Since my connection was not behind a proxy, removing/editing proxy configurations didn't make sense. And I didn't want to delete a file or uninstall PMC either. While looking around I realized a "Clear All Nuget Cache(s)" button on Tools --> Options --> NuGet Package Manager --> General. After pressing the button I had to wait for some time for the operation to complete. After that I tried to scaffold the Identity again but it didn't work. Then I decided to restart VS and voila :)