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

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

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


当前回答

在我的情况下,我失去了与Git的连接。我只是再次添加连接,它工作!:

其他回答

这也可能由于身份验证问题而发生,因此您可能需要重新对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中更新我的密码!

I had changed my work Microsoft account password last week or so, I also use that account to login to visual studio, however I wasn't prompted to update it and was not logged out of Visual Studio, it remained logged in. When I clicked on my initials in the top right of visual studio > Account settings > under All Accounts the work account had yellow exclamation triangle warning sign next to it, updated the new password, then updated some packages, dotnet restore, cleaned & rebuilt and the errors are gone.

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

也许这有帮助

对我来说,删除位于C:\Users\YourNameHere的.nuget文件夹解决了这个问题。

如果有人仍然有问题,NuGet答案不工作。下面的答案对我(一家DevOps Azure托管TFS的公司)来说是有效的:登录和退出团队基金会。TFS和VS都报告为已登录,但情况并非如此。不得不辞职——与op描述的症状相同。详情请参阅此答案。