部署IronPDF NuGet 套件:修正

This article was translated from English: Does it need improvement?
Translated
View the article in English

在嘗試部署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現在要求安全連接。

解決方案

  1. 安裝Visual C++執行時庫: 確保您的系統上安裝了Visual Studio 的Visual C++ Redistributable。 缺少運行時可能會導致某些套件出現問題,包括IronPDF。

  2. 更新Visual Studio: 確保您使用的是一個最近的、最新的Visual Studio版本。 需Visual Studio 2015或更高版本才能正確支持現代的TLS協定。

    • 在Visual Studio中,前往:
      • 工具 > 延伸與更新 > 更新 > Visual Studio Gallery
      • 將NuGet套件管理器更新到最新版本。
  3. 在.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
      • 上述的登錄檔項允許在.NET的32位和64位版本中使用強加密。
    2. 執行.reg文件以更新登錄檔設置。 這會在.NET啟用強加密,允許TLS 1.2連接。

不需要重新啟動。 應用這些變更後,嘗試再次運行您的NuGet命令。

詳細資訊,請參閱這篇Stack Overflow貼文:NuGet失敗:基礎連接已關閉:發生意外錯誤。

如果您需要進一步協助,請提交工程請求與我們聯繫。

Curtis Chau
技術作家

Curtis Chau擁有Carleton大學的電腦科學學士學位,專精於前端開發,擁有Node.js、TypeScript、JavaScript和React的專業知識。Curtis熱衷於建立直觀且美觀的使用者介面,喜愛使用現代框架並建立結構良好、視覺吸引力的手冊。

除了開發,Curtis對物聯網(IoT)有濃厚的興趣,探索創新的方法來整合硬體和軟體。在空閒時間,他喜歡玩遊戲和建立Discord機器人,結合他對技術的熱愛與創造力。

準備開始了嗎?
Nuget 下載 20,296,129 | 版本: 2026.7 剛剛發布
Still Scrolling Icon

還在捲動嗎?

想快速獲得證明嗎? PM > Install-Package IronPdf
執行範例 看您的HTML變成PDF。