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

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

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


当前回答

nuget restore 

and

msbuild /t:restore

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

dotnet restore 

完美的工作。试试

其他回答

转到%appdata%\NuGet\NuGet.config 修改这一行: < packageSources > <add key="Microsoft Visual Studio Offline Packages" value="C:\Program Files (x86)\Microsoft sdk \NuGetPackages\" /> . <add key="Package source" value="https://api.nuget.org/v3/index.json" /> . < / packageSources >

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

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

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

我希望这对你有用。  

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

我在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.

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

新包管理器的开发人员在2019年建议禁用tls 1.3作为解决方案(见第7705期)。

通过按Win + R打开注册表编辑器,并键入regedit Enter

导航到:

\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Client

将“DisabledByDefault key 0”的值修改为1

然后重新启动Visual Studio。

在维基百科上阅读更多关于TLS的信息 阅读更多关于问题7705 w.r.t. NuGet在github

第三方编辑

请注意,这将禁用操作系统的tls 1.3,而不仅仅是对nuget或dotnet。 Windows 10 1909版确实包含TLS 1.3的实验性实现,但后续版本应该没问题。基于无法浏览nuget包的一个答案,您可以通过控制台程序测试tls是否存在问题

static async Task Main(string[] args)
{
    var client = new HttpClient();
    string uri = "https://apiint.nugettest.org/v3-index/index.json";
    var response = await client.GetAsync(uri);
    string msg = "If you see this, your machine has no TLS/SSL issues with nuget.org";
    Console.WriteLine(msg);

}