部署 IronPDF 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 命令可能會失敗。
如果未啟用 TLS 1.2,從 HTTP 切換到 HTTPS 不會解決問題,因為 NuGet 現在要求安全連接。
解決方案
安裝 Visual C++ 運行庫:
确保Visual Studio 的 Visual C++ Redistributable已安裝在您的系統上。 缺少運行時可能會導致某些包括IronPDF在內的包出現問題。
更新 Visual Studio:
請確保您使用的是最新的 Visual Studio 版本。 Visual Studio 2015 或更高版本是支持现代TLS协议所必需的。
在 Visual Studio 中,前往:
工具 > 擴充功能和更新 > 更新 > Visual Studio 藝廊
- 將 NuGet 套件管理員更新至最新版本。
在 .NET 中啟用強大的加密技術:
如果上述步驟無法解決問題,您可能需要在 .NET 中啟用強加密。 這可以通過修改註冊表來完成。
- 建立一個包含以下內容的
.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 失敗:基礎連線已關閉:發生意外錯誤。
聯絡我們,請提交工程需求如果您需要進一步的協助。