部署 NuGet 包失败
在尝试部署 NuGet 包时,您可能会看到以下一条或多条错误消息:
Failed to deploy NuGet package '_IronPdf.Native.Chrome.Windows(version)'
System.Net.WebException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send.
System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
可能原因
这些错误最常见的原因是与过时的 TLS 协议有关。自2020年6月15日起, NuGet 已经停止支持 TLS 1.0 和 1.1, 并且现在强制使用 TLS 1.2。如果您的系统未启用 TLS 1.2,NuGet 命令可能会失败。
切换从 HTTP 到 HTTPS 如果没有启用 TLS 1.2 不会解决问题,因为 NuGet 现在需要安全连接。
解决方案
- 安装 Visual C++ 运行时:
确保 Visual C++ Redistributable for Visual Studio 安装在您的系统上。缺少运行时可能会导致某些软件包出现问题,包括 IronPDF。
- 更新 Visual Studio:
确保您使用的是最新的 Visual Studio 版本。需要 Visual Studio 2015 或更高版本才能正确支持现代的 TLS 协议。
1. 在 Visual Studio 中,前往:
- 工具 > 扩展和更新 > 更新 > Visual Studio Gallery
- 将 NuGet 包管理器更新到最新版本。
- 在 .NET 中启用强加密:
如果上述步骤未能解决问题,您可能需要在 .NET 中启用强加密。这可以通过修改注册表来完成。
1. 创建一个 `.reg` 文件,并添加以下内容:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319]
"SchUseStrongCrypto"=dword:00000001
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v4.0.30319]
"SchUseStrongCrypto"=dword:00000001
- 运行
.reg
文件以更新注册表设置。这启用 .NET 中的强加密,从而允许 TLS 1.2 连接。
无需重启。应用这些更改后,尝试再次运行 NuGet 命令。
有关更多详细信息,请参阅此 Stack Overflow 帖子: NuGet 失败:基础连接已关闭:发生了意外错误。
通过提交联系我们 工程要求 如需进一步帮助。