Windows 上 .NET Core 的必要條件Prerequisites for .NET Core on Windows

本文會說明在 Windows 開發 .NET Core 應用程式所需的相依性。This article shows the dependencies needed to develop .NET Core applications on Windows. 支援的作業系統版本和跟隨的相依性,適用於在 Windows 開發 .NET Core 應用程式的三種方式:The supported OS versions and dependencies that follow apply to the three ways of developing .NET Core apps on Windows:

.NET Core 支援的 Windows 版本.NET Core supported Windows versions

下列版本支援 .NET Core:.NET Core is supported on the following versions of:

  • Windows 7 SP1Windows 7 SP1
  • Windows 8.1Windows 8.1
  • Windows 10 年度更新 (1607 版) 或更新版本Windows 10 Anniversary Update (version 1607) or later versions
  • Windows Server 2008 R2 SP1 (完整伺服器或 Server Core)Windows Server 2008 R2 SP1 (Full Server or Server Core)
  • Windows Server 2012 SP1 (完整伺服器或 Server Core)Windows Server 2012 SP1 (Full Server or Server Core)
  • Windows Server 2012 R2 (完整伺服器或 Server Core)Windows Server 2012 R2 (Full Server or Server Core)
  • Windows Server 2016 或更新版本 (完整伺服器、Server Core 或 Nano Server)Windows Server 2016 or later versions (Full Server, Server Core, or Nano Server)

以下文件有 .NET Core 所支援每個版本作業系統的完整清單:The following articles have a complete list of .NET Core supported operating systems per version:

.NET Core 的相依性.NET Core dependencies

在 Windows 10 和 Windows Server 2016 之前的 Windows 版本上執行時,.NET Core 1.1 和舊版本需要 Visual C++ 可轉散發套件。.NET Core 1.1 and earlier versions require the Visual C++ Redistributable when running on Windows versions earlier than Windows 10 and Windows Server 2016. .NET Core 安裝程式會自動安裝此相依性。This dependency is automatically installed by the .NET Core installer.

必須手動安裝 Microsoft Visual C++ 2015 可轉散發套件 Update 3 的時機:Microsoft Visual C++ 2015 Redistributable Update 3 must be manually installed when:

  • 使用安裝程式指令碼安裝 .NET Core。Installing .NET Core with the installer script.
  • 部署獨立的 .NET Core 應用程式。Deploying a self-contained .NET Core application.
  • 從來源建置產品。Building the product from source.
  • 透過 .zip 檔案安裝 .NET Core。Installing .NET Core via a .zip file. 這可以包含組建/CI/CD 伺服器。This can include build/CI/CD servers.

注意

適用於 Windows 8.1 和更早版本,或 Windows Server 2012 R2 和更早版本:For Windows 8.1 and earlier versions, or Windows Server 2012 R2 and earlier versions:

請確定您的 Windows 安裝處於最新狀態,且包含 KB2999226 (機器翻譯) (可透過 Windows Update 安裝)。Make sure that your Windows installation is up-to-date and includes KB2999226, which can be installed through Windows Update. 如果沒有安裝此更新,當您啟動 .NET Core 應用程式時,將會看到如下的錯誤:The program can't start because api-ms-win-crt-runtime-1-1-0.dll is missing from your computer. Try reinstalling the program to fix this problem.If you don't have this update installed, you'll see an error like the following when you launch a .NET Core application: The program can't start because api-ms-win-crt-runtime-1-1-0.dll is missing from your computer. Try reinstalling the program to fix this problem.

適用於 Windows 7 或 Windows Server 2008 R2:For Windows 7 or Windows Server 2008 R2:

除了 KB2999226,請確定您也已經安裝 KB2533623In addition to KB2999226, make sure you also have KB2533623 installed. 如果沒有安裝此更新,當您啟動 .NET Core 應用程式時,將會看到如下的錯誤:The library hostfxr.dll was found, but loading it from C:\<path_to_app>\hostfxr.dll failedIf you don't have this update installed, you'll see an error similar to the following when you launch a .NET Core application: The library hostfxr.dll was found, but loading it from C:\<path_to_app>\hostfxr.dll failed.

使用 Visual Studio 2017 的必要條件Prerequisites with Visual Studio 2017

您可以使用任何編輯器來開發使用 .NET Core SDK 的 .NET Core 應用程式。You can use any editor to develop .NET Core applications using the .NET Core SDK. Visual Studio 2017 為 Windows 上的 .NET Core 應用程式提供整合式開發環境。Visual Studio 2017 provides an integrated development environment for .NET Core apps on Windows.

您可以在版本資訊中,進一步了解 Visual Studio 2017 的變更。You can read more about the changes in Visual Studio 2017 in the release notes.

若要在 Visual Studio 2017 中開發 .NET Core 2.x 應用程式:To develop .NET Core 2.x apps in Visual Studio 2017:

  1. 下載並安裝 Visual Studio 2017 15.3.0 版本或更高版本,選取 [.NET Core 跨平台開發] 工作負載 (在 [其他工具組] 區段)。Download and install Visual Studio 2017 version 15.3.0 or higher with the .NET Core cross-platform development workload (in the Other Toolsets section) selected.

已選取 [.NET Core 跨平台開發] 工作負載的 Visual Studio 2017 安裝螢幕擷取畫面

安裝 .NET Core 跨平台開發工具集之後,Visual Studio 2017 預設使用 .NET Core 1.x。After the .NET Core cross-platform development toolset is installed, Visual Studio 2017 uses .NET Core 1.x by default. 安裝 .NET Core 2.x SDK 以取得 Visual Studio 2017 中的 .NET Core 2.x 支援。Install the .NET Core 2.x SDK to get .NET Core 2.x support in Visual Studio 2017.

  1. 安裝 .NET Core 2.x SDKInstall the .NET Core 2.x SDK.
  2. 使用下列指示將現有或新的 .NET Core 1.x 專案目標重定到 .NET Core 2.x:Retarget existing or new .NET Core 1.x projects to .NET Core 2.x using the following instructions:
    • 在 [專案] 功能表上,選擇 [屬性]。On the Project menu, Choose Properties.
    • 在 [目標 Framework] 選取功能表中,將值設為 .NET Core 2.0In the Target framework selection menu, set the value to .NET Core 2.0.

螢幕擷取畫面:選取 ".NET Core 2.0" 目標 Framework 功能表項目的 Visual Studio 2017 應用程式專案屬性

一旦安裝 .NET Core 2.x SDK,Visual Studio 2017 預設會使用 .NET Core SDK 2.x,而且支援下列動作:Once the .NET Core 2.x SDK is installed, Visual Studio 2017 uses the .NET Core SDK 2.x by default, and supports the following actions:

  • 開啟、建置及執行現有的 .NET Core 1.x 專案。Open, build, and run existing .NET Core 1.x projects.
  • 將 .NET Core 1.x 專案重定目標至 .NET Core 2.x、建置和執行。Retarget .NET Core 1.x projects to .NET Core 2.x, build, and run.
  • 建立新的 .NET Core 2.x 專案。Create new .NET Core 2.x projects.

提示

確認 Visual Studio 2017 版本:To verify your Visual Studio 2017 version:

  • [說明] 功能表上,選擇 [關於 Microsoft Visual Studio]On the Help menu, choose About Microsoft Visual Studio.
  • 在 [關於 Microsoft Visual Studio] 對話方塊中,確認版本號碼。In the About Microsoft Visual Studio dialog, verify the version number.
    • 對於 .NET Core 2.1 RC 應用程式,需要 Visual Studio 2017 15.7 版或更高版本。For .NET Core 2.1 RC apps, Visual Studio 2017 version 15.7 or higher.
    • 若為 .NET Core 2.0 應用程式,需要 Visual Studio 2017 版本 15.3 或更高版本。For .NET Core 2.0 apps, Visual Studio 2017 version 15.3 or higher.
    • 若為 .NET Core 1.x 應用程式,需要 Visual Studio 2017 版本 15.0 或更高版本。For .NET Core 1.x apps, Visual Studio 2017 version 15.0 or higher.