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

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

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


当前回答

如果您得到此错误,但没有代理服务器,则可以转到

%userprofile%\AppData\Roaming\NuGet\NuGet.Config

并注释这行:

<config>
     <!-- Proxy settings -->
     <add key="http_proxy" value="host" />
     <add key="http_proxy.user" value="username" />
     <add key="http_proxy.password" value="encrypted_password" />
</config>

它为我工作,因为我得到了这个错误,但我没有代理服务器。

其他回答

我通过安装IISCrypto并在命令行上运行来修复这个问题:

IISCryptoCli.exe /template default /reboot

当我试图通过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"

我删除了%localappdata%/Nuget中的所有内容,并清除了NuGets缓存。

dotnet nuget locals all --clear

重新启动后,Visual studio 2022恢复了我的包。

我有这个错误,然后我意识到我是用我的个人微软帐户而不是我的工作帐户登录的。

希望这能有所帮助。

有些开发环境可能既不使用浏览器也不使用代理。

一种解决方案是从nugget(例如https://dotnet.myget.org/F/dotnet-core/api/v3/index.json)下载包到共享目录,然后执行以下操作:

dotnet add package Microsoft.AspNetCore.StaticFiles -s "shared drive:\index.json"

我希望这对你有用。