部署 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 Gallery
- 將 NuGet 套件管理員更新至最新版本。
- 在 Visual Studio 中,請前往:
-
在 .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- 上述登錄檔項目可讓 .NET 在 32 位元與 64 位元版本中皆能使用強加密技術。
- 執行
.reg檔案以更新登錄設定。 此功能可在 .NET 中啟用強加密機制,並支援 TLS 1.2 連線。
-
無需重新啟動。 套用這些變更後,請嘗試再次執行您的 NuGet 指令。
如需更多詳細資訊,請參閱這篇 Stack Overflow 貼文:NuGet 失敗:底層連線已關閉:發生意外錯誤。
若需進一步協助,請透過提交工程請求與我們聯繫。

