部署 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++ 可轉發套件。 缺少運行時可能會導致某些包括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 出現錯誤:基礎連接已關閉:發生了意外錯誤。
如需進一步協助,請提交工程請求與我們聯繫。