Visual Studio与NuGet新手求助:无法检索NuGet包信息错误
NuGet无法检索包信息的解决方案
问题分析
从你提供的控制台日志来看,核心问题是无法与NuGet.org建立SSL连接,具体错误提示为:
无法建立SSL连接,详见内部异常。无法向传输连接写入数据:套接字未连接。
这通常和网络环境、代理设置、SSL证书或NuGet配置有关,咱们一步步来解决。
具体解决步骤
先排查网络和代理
首先确认你的网络能正常访问NuGet.org。如果是在公司/学校这类受限网络下,大概率是代理拦截了SSL请求,可以试试切换到个人热点测试。另外检查Visual Studio的NuGet代理设置:- 打开VS,点击
工具 > 选项 > NuGet包管理器 > 包源 - 点击右上角的齿轮图标进入设置,要么确认代理信息正确,要么暂时关闭代理再尝试还原。
- 打开VS,点击
更新NuGet和.NET SDK版本
旧版本的NuGet客户端或.NET SDK可能存在SSL兼容性问题,建议更新到最新版本:- 在VS里打开
工具 > 获取工具和功能,确保安装了最新的NuGet组件 - 或者在终端运行
dotnet nuget update source来刷新NuGet源配置
- 在VS里打开
检查本地SSL证书
本地SSL证书存储异常也会导致连接失败:- 打开终端,运行
curl -v https://api.nuget.org/v3-flatcontainer/system.net.http/index.json,看看是否能正常返回内容 - 如果提示证书错误,根据你的系统重置证书存储:
- macOS:可以用
security delete-certificate -Z <证书哈希值>(先通过security find-certificate -a -p | openssl x509 -hash -noout找到对应证书哈希) - Windows:运行
certutil -syncWithWU同步Windows更新的证书
- macOS:可以用
- 打开终端,运行
重新配置NuGet源
尝试删除默认的NuGet.org源,再重新添加:
在终端执行以下命令:dotnet nuget remove source nuget.org dotnet nuget add source https://api.nuget.org/v3/index.json --name nuget.org
你的错误日志详情
获取项目/Users/{USERNAME}/Pfeife/Pfeife/Pfeife.csproj的还原信息 获取项目/Users/{USERNAME}/Pfeife/Pfeife.iOS/Pfeife.iOS.csproj的还原信息 获取项目/Users/{USERNAME}/Pfeife/Pfeife.Android/Pfeife.Android.csproj的还原信息 运行非并行还原。 读取项目文件/Users/{USERNAME}/Pfeife/Pfeife/Pfeife.csproj。 将无操作dg保存到/Users/{USERNAME}/Pfeife/Pfeife/obj/Pfeife.csproj.nuget.dgspec.json 正在为/Users/{USERNAME}/Pfeife/Pfeife/Pfeife.csproj还原包... 正在为.NETStandard,Version=v2.0还原包... GET https://api.nuget.org/v3-flatcontainer/system.net.http/index.json 重试针对源'https://api.nuget.org/v3-flatcontainer/system.net.http/index.json'的'FindPackagesByIdAsync'。 无法建立SSL连接,详见内部异常。 无法向传输连接写入数据:套接字未连接。 套接字未连接 GET https://api.nuget.org/v3-flatcontainer/system.net.http/index.json 重试针对源'https://api.nuget.org/v3-flatcontainer/system.net.http/index.json'的'FindPackagesByIdAsync'。 无法建立SSL连接,详见内部异常。 无法向传输连接写入数据:套接字未连接。 套接字未连接 GET https://api.nuget.org/v3-flatcontainer/system.net.http/index.json 无法从远程源'https://api.nuget.org/v3-flatcontainer/system.net.http/index.json'检索'System.Net.Http'的信息。
内容的提问来源于stack exchange,提问作者Soteri




