MSBuild 目標 Framework 和目標平台MSBuild target framework and target platform

您可以建置專案,以在特定 .NET Framework 版本的「目標 Framework」,以及特定軟體架構的「目標平台」上執行。A project can be built to run on a target framework, which is a particular version of the .NET Framework, and a target platform, which is a particular software architecture. 例如,您可以在目標為 .NET Framework 2.0 以及與 802x86 處理器系列 ("x86") 相容的 32 位元平台上,執行應用程式。For example, you can target an application to run on the .NET Framework 2.0 on a 32-bit platform that is compatible with the 802x86 processor family ("x86"). 目標 Framework 和目標平台的組合稱為「目標內容」。The combination of target framework and target platform is known as the target context.

Important

本文說明指定目標 Framework 的舊方式。This article shows the old way to specify a target framework. SDK 樣式專案可啟用不同的 TargetFrameworks,例如 netstandard。SDK-style projects enable different TargetFrameworks like netstandard. 如需詳細資訊,請參閱目標 FrameworkFor more info, see Target frameworks.

目標 Framework 和設定檔Target framework and profile

目標 Framework 是專案被建置來於其上執行的特定 .NET Framework 版本。A target framework is the particular version of the .NET Framework that your project is built to run on. 由於目標 Framework 啟用由該版 Framework 獨佔的編譯器功能和組件參考,因此需要目標 Framework 的規格。Specification of a target framework is required because it enables compiler features and assembly references that are exclusive to that version of the framework.

以下是目前可供使用的 .NET Framework 版本:Currently, the following versions of the .NET Framework are available for use:

  • .NET Framework 2.0 (包含在 Visual Studio 2005 中)The .NET Framework 2.0 (included in Visual Studio 2005)

  • .NET Framework 3.0 (包含在 Windows VistaWindows Vista 中)The .NET Framework 3.0 (included in Windows VistaWindows Vista)

  • .NET Framework 3.5 (包含在 Visual Studio 2008Visual Studio 2008 中)The .NET Framework 3.5 (included in Visual Studio 2008Visual Studio 2008)

  • .NET Framework 4.5.2The .NET Framework 4.5.2

  • .NET Framework 4.6 (包含在 Visual Studio 2015Visual Studio 2015 中)The .NET Framework 4.6 (included in Visual Studio 2015Visual Studio 2015)

  • .NET Framework 4.6.1The .NET Framework 4.6.1

  • .NET Framework 4.6.2The .NET Framework 4.6.2

  • .NET Framework 4.7The .NET Framework 4.7

  • .NET Framework 4.7.1The .NET Framework 4.7.1

  • .NET Framework 4.7.2The .NET Framework 4.7.2

  • .NET Framework 4.8The .NET Framework 4.8

組件清單中每一個組件所參考的 .NET Framework 版本各自不同。The versions of the .NET Framework differ from one another in the list of assemblies that each makes available to reference. 例如,除非您專案是以 .NET Framework 3.0 (含) 以上版本為目標,否則您無法建置 Windows Presentation Foundation (WPF) 應用程式。For example, you cannot build Windows Presentation Foundation (WPF) applications unless your project targets the .NET Framework version 3.0 or above.

目標 Framework 是在專案檔的 TargetFrameworkVersion 屬性中指定。The target framework is specified in the TargetFrameworkVersion property in the project file. 您可以在 Visual Studio 整合式開發環境 (IDE) 中,使用專案屬性頁來變更專案的目標 Framework。You can change the target framework for a project by using the project property pages in the Visual Studio integrated development environment (IDE). 如需詳細資訊,請參閱如何:以 .NET Framework 版本為目標For more information, see How to: Target a version of the .NET Framework. TargetFrameworkVersion 的可用值包括 v2.0v3.0v3.5v4.5.2v4.6v4.6.1v4.6.2v4.7v4.7.1v4.7.2v4.8The available values for TargetFrameworkVersion are v2.0, v3.0, v3.5, v4.5.2, v4.6, v4.6.1, v4.6.2, v4.7, v4.7.1, v4.7.2, and v4.8.

<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>

「目標設定檔」是目標 Framework 的子集。A target profile is a subset of a target framework. 例如,.NET Framework 4 用戶端設定檔不包含 MSBuild 組件的參考。For example, the .NET Framework 4 Client profile does not include references to the MSBuild assemblies.

Note

目標設定檔僅適用于可移植的類別庫Target profiles apply only to portable class libraries.

目標設定檔是在專案檔的 TargetFrameworkProfile 屬性中指定。The target profile is specified in the TargetFrameworkProfile property in a project file. 您可以在 IDE 中,使用專案屬性頁中的目標 Framework 控制項來變更目標設定檔。You can change the target profile by using the target-framework control in the project property pages in the IDE.

<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>

目標平台Target platform

「平台」是定義特定執行階段環境的軟硬體組合。A platform is combination of hardware and software that defines a particular runtime environment. 例如,套用至物件的For example,

  • x86 指定在 Intel 80x86 處理器或其對等項目上執行的 32 位元 Windows 作業系統。x86 designates a 32-bit Windows operating system that is running on an Intel 80x86 processor or its equivalent.

  • x64 指定在 Intel x64 處理器或其對等項目上執行的 64 位元 Windows 作業系統。x64 designates a 64-bit Windows operating system that is running on an Intel x64 processor or it equivalent.

  • Xbox 指定 Microsoft Xbox 360 平台。Xbox designates the Microsoft Xbox 360 platform.

「目標平台」是建置專案以在其上方執行的目標特定平台。A target platform is the particular platform that your project is built to run on. 目標平台是在專案檔的 PlatformTarget 建置屬性中指定。The target platform is specified in the PlatformTarget build property in a project file. 您可以在 IDE 中,使用專案屬性頁或 [組態管理員] 來變更目標平台。You can change the target platform by using the project property pages or the Configuration Manager in the IDE.

<PropertyGroup>
   <PlatformTarget>x86</PlatformTarget>
</PropertyGroup>

「目標組態」是目標平台的子集。A target configuration is a subset of a target platform. 例如,x86``Debug 組態不包含大部分的程式碼最佳化。For example, the x86``Debug configuration does not include most code optimizations. 目標組態是在專案檔的 Configuration 建置屬性中指定。The target configuration is specified in the Configuration build property in a project file. 您可以使用專案屬性頁或 [組態管理員] 來變更目標組態。You can change the target configuration by using the project property pages or the Configuration Manager.

<PropertyGroup>
   <PlatformTarget>x86</PlatformTarget>
   <Configuration>Debug</Configuration>
<PropertyGroup>

請參閱See also