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

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

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


当前回答

好吧,我尝试了上面所有的答案,希望我的注册表现在不是软管。但这似乎解决了我的问题:

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个小时寻找解决方案的人!!

其他回答

我在Visual Studio 2015上执行Install-Package Modernizr时遇到了类似的问题。我通过以下步骤解决了这个问题:

Download the package from its online source. Go to Tools/NuGet Package Manager/Package Manager Settings. Select Package Sources from the window. Add a new package source by clicking on the + sign. Enter a name and source location by clicking on ... (triple dot) sign. Make sure that only the package source that you've just added is checked. Uncheck all the other package sources. Go to Package Manager Console and type Install-Package Modernizr. Visual Studio 2015 installs the package automatically and creates Scripts and packages folders in your root folder.

我希望同样的解决方案在安装其他包时也能起作用。

nuget restore 

and

msbuild /t:restore

两者都没有为我工作,因为同样的错误。但

dotnet restore 

完美的工作。试试

当我试图通过Jenkins(配置为服务,默认使用本地系统帐户)运行nuget.exe时,我偶然发现了这个问题。我已经编辑了C:\Windows\System32\config\systemprofile\AppData\Roaming\NuGet\NuGet。配置文件,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <config>
        <add key="http_proxy" value="http://proxy_hostname_or_ip:3128" />
        <add key="https_proxy" value="http://proxy_hostname_or_ip:3128" />
    </config>

  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
  </packageSources>

</configuration> 

为了测试命令提示符,可以通过PSTools启动:

psexec -i -s CMD

和实际测试运行在新创建的cmd窗口(运行为本地系统):

path_to_nuget\nuget.exe restore "path_to_solution\theSolution.sln"

我使用VSO/Azure DevOps。

您也可以直接在浏览器中访问提要url。你最终可能会得到这样的回复,这可能会让你的诊断更快:

用户没有使用ms.feed扩展名的许可证。

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