SDK スタイルのプロジェクトでのターゲット フレームワークTarget frameworks in SDK-style projects
アプリまたはライブラリでフレームワークをターゲットに設定するときは、アプリまたはライブラリで使用できるようにする API のセットを指定します。When you target a framework in an app or library, you're specifying the set of APIs that you'd like to make available to the app or library. プロジェクト ファイルでターゲット フレームワークを指定するには、ターゲット フレームワーク モニカー (TFM) を使います。You specify the target framework in your project file using Target Framework Monikers (TFMs).
アプリまたはライブラリでは、.NET Standard のバージョンをターゲットにできます。An app or library can target a version of .NET Standard. .NET Standard のバージョンは、.NET のすべての実装で標準化された API のセットを表します。.NET Standard versions represent standardized sets of APIs across all .NET implementations. たとえば、ライブラリは、.NET Standard 1.6 をターゲットにして、.NET Core と .NET Framework で機能する API に同じコードベースを使ってアクセスできます。For example, a library can target .NET Standard 1.6 and gain access to APIs that function across .NET Core and .NET Framework using the same codebase.
また、アプリまたはライブラリは、.NET の特定の実装をターゲットにして、実装固有の API にアクセスすることもできます。An app or library can also target a specific .NET implementation to gain access to implementation-specific APIs. たとえば、Xamarin.iOS (たとえば Xamarin.iOS10
) をターゲットにするアプリは Xamarin が提供する iOS 10 用の iOS API ラッパーにアクセスでき、ユニバーサル Windows プラットフォーム (UWP、uap10.0
) をターゲットにするアプリは Windows 10 を実行するデバイス用にコンパイルできる API にアクセスできます。For example, an app that targets Xamarin.iOS (for example, Xamarin.iOS10
) gets access to Xamarin-provided iOS API wrappers for iOS 10, or an app that targets the Universal Windows Platform (UWP, uap10.0
) has access to APIs that compile for devices that run Windows 10.
一部のターゲット フレームワーク (.NET Framework など) では、API はフレームワークがシステムにインストールするアセンブリによって定義され、アプリケーション フレームワーク API (たとえば ASP.NET) を含む場合があります。For some target frameworks (for example, the .NET Framework), the APIs are defined by the assemblies that the framework installs on a system and may include application framework APIs (for example, ASP.NET).
パッケージ ベースのターゲット フレームワーク (.NET Standard、.NET Core など) では、API はアプリまたはライブラリに含まれるパッケージによって定義されます。For package-based target frameworks (for example, .NET Standard and .NET Core), the APIs are defined by the packages included in the app or library. "メタパッケージ" は、それ独自の内容はなく、依存するもの (他のパッケージ) のリストを保持している NuGet パッケージです。A metapackage is a NuGet package that has no content of its own but is a list of dependencies (other packages). NuGet パッケージ ベースのターゲット フレームワークでは、全体としてフレームワークを構成するすべてのパッケージを参照するメタパッケージが暗黙的に指定されます。A NuGet package-based target framework implicitly specifies a metapackage that references all the packages that together make up the framework.
最新のターゲット フレームワークのバージョンLatest target framework versions
次の表では、最も一般的なターゲット フレームワーク、それらの参照方法、およびそれらが実装する .NET Standard のバージョンを定義します。The following table defines the most common target frameworks, how they're referenced, and which version of the .NET Standard they implement. これらのターゲット フレームワークのバージョンは、最新の安定したバージョンです。These target framework versions are the latest stable versions. プレリリース バージョンは記載されていません。Pre-release versions aren't shown. ターゲット フレームワーク モニカー (TFM) は、.NET アプリまたはライブラリのターゲット フレームワークを指定するための標準化されたトークン形式です。A Target Framework Moniker (TFM) is a standardized token format for specifying the target framework of a .NET app or library.
[対象とする Framework]Target Framework | LatestLatest 安定バージョンStable Version |
ターゲット フレームワーク モニカー (TFM)Target Framework Moniker (TFM) | 実装済みImplemented .NET Standard バージョン.NET Standard Version |
---|---|---|---|
.NET Standard.NET Standard | 2.12.1 | netstandard2.1netstandard2.1 | N/AN/A |
.NET Core.NET Core | 3.13.1 | netcoreapp3.1netcoreapp3.1 | 2.12.1 |
.NET Framework.NET Framework | 4.84.8 | net48net48 | 2.02.0 |
サポートされるターゲット フレームワークのバージョンSupported target framework versions
ターゲット フレームワークは、通常、TFM によって参照されます。A target framework is typically referenced by a TFM. 次の表では、.NET Core SDK および NuGet クライアントによってサポートされるターゲット フレームワークを示します。The following table shows the target frameworks supported by the .NET Core SDK and the NuGet client. 同等のものがかっこ内に示されています。Equivalents are shown within brackets. たとえば、win81
は netcore451
と同等の TFM です。For example, win81
is an equivalent TFM to netcore451
.
[対象とする Framework]Target Framework | TFMTFM |
---|---|
.NET Standard.NET Standard | netstandard1.0netstandard1.0 netstandard1.1netstandard1.1 netstandard1.2netstandard1.2 netstandard1.3netstandard1.3 netstandard1.4netstandard1.4 netstandard1.5netstandard1.5 netstandard1.6netstandard1.6 netstandard2.0netstandard2.0 netstandard2.1netstandard2.1 |
.NET Core.NET Core | netcoreapp1.0netcoreapp1.0 netcoreapp1.1netcoreapp1.1 netcoreapp2.0netcoreapp2.0 netcoreapp2.1netcoreapp2.1 netcoreapp2.2netcoreapp2.2 netcoreapp3.0netcoreapp3.0 netcoreapp3.1netcoreapp3.1 |
.NET Framework.NET Framework | net11net11 net20net20 net35net35 net40net40 net403net403 net45net45 net451net451 net452net452 net46net46 net461net461 net462net462 net47net47 net471net471 net472net472 net48net48 |
Windows ストアWindows Store | netcore [netcore45]netcore [netcore45] netcore45 [win] [win8]netcore45 [win] [win8] netcore451 [win81]netcore451 [win81] |
.NET Micro Framework.NET Micro Framework | netmfnetmf |
SilverlightSilverlight | sl4sl4 sl5sl5 |
Windows PhoneWindows Phone | wp [wp7]wp [wp7] wp7wp7 wp75wp75 wp8wp8 wp81wp81 wpa81wpa81 |
ユニバーサル Windows プラットフォームUniversal Windows Platform | uap [uap10.0]uap [uap10.0] uap10.0 [win10] [netcore50]uap10.0 [win10] [netcore50] |
ターゲット フレームワークを指定する方法How to specify target frameworks
ターゲット フレームワークはプロジェクト ファイルで指定します。Target frameworks are specified in your project file. 単一のターゲット フレームワークを指定するときは、TargetFramework 要素を使います。When a single target framework is specified, use the TargetFramework element. 次のコンソール アプリのプロジェクト ファイルでは、.NET Core 3.0 をターゲットにする方法が示されています。The following console app project file demonstrates how to target .NET Core 3.0:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
</Project>
複数のターゲット フレームワークを指定するときは、各ターゲット フレームワークに対するアセンブリを条件付きで参照できます。When you specify multiple target frameworks, you may conditionally reference assemblies for each target framework. コードでは、プリプロセッサ シンボルと if-then-else ロジックを使うことで、これらのアセンブリに対して条件付きでコンパイルできます。In your code, you can conditionally compile against those assemblies by using preprocessor symbols with if-then-else logic.
次のライブラリ プロジェクト ファイルは、.NET Standard (netstandard1.4
) の API と、.NET Framework (net40
および net45
) の API をターゲットにしています。The following library project file targets APIs of .NET Standard (netstandard1.4
) and APIs of the .NET Framework (net40
and net45
). ターゲット フレームワークが複数あるときは、複数形の TargetFrameworks 要素を使います。Use the plural TargetFrameworks element with multiple target frameworks. ライブラリが 2 つの .NET Framework TFM に対してコンパイルされるときに Condition
属性で実装固有のパッケージを指定する方法に注意してください。Note how the Condition
attributes include implementation-specific packages when the library is compiled for the two .NET Framework TFMs:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard1.4;net40;net45</TargetFrameworks>
</PropertyGroup>
<!-- Conditionally obtain references for the .NET Framework 4.0 target -->
<ItemGroup Condition=" '$(TargetFramework)' == 'net40' ">
<Reference Include="System.Net" />
</ItemGroup>
<!-- Conditionally obtain references for the .NET Framework 4.5 target -->
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
<Reference Include="System.Net.Http" />
<Reference Include="System.Threading.Tasks" />
</ItemGroup>
</Project>
ライブラリまたはアプリ内では、各ターゲット フレームワーク用にコンパイルするための条件付きコードを記述します。Within your library or app, you write conditional code to compile for each target framework:
public class MyClass
{
static void Main()
{
#if NET40
Console.WriteLine("Target framework: .NET Framework 4.0");
#elif NET45
Console.WriteLine("Target framework: .NET Framework 4.5");
#else
Console.WriteLine("Target framework: .NET Standard 1.4");
#endif
}
}
SDK スタイル プロジェクトを使用する場合、ビルド システムは、「サポートされるターゲット フレームワークのバージョン」の表で示されているターゲット フレームワークを表すプリプロセッサ シンボルを認識します。The build system is aware of preprocessor symbols representing the target frameworks shown in the Supported target framework versions table when you're using SDK-style projects. .NET Standard または .NET Core の TFM を表すシンボルを使うときは、ドットをアンダースコアに置き換え、小文字を大文字に変更します (たとえば、netstandard1.4
のシンボルは NETSTANDARD1_4
です)。When using a symbol that represents a .NET Standard or .NET Core TFM, replace the dot with an underscore and change lowercase letters to uppercase (for example, the symbol for netstandard1.4
is NETSTANDARD1_4
).
.NET Core ターゲット フレームワークのプリプロセッサ シンボルの完全な一覧を次に示します。The complete list of preprocessor symbols for .NET Core target frameworks is:
ターゲット フレームワークTarget Frameworks | シンボルSymbols |
---|---|
.NET Framework.NET Framework | NETFRAMEWORK , NET20 , NET35 , NET40 , NET45 , NET451 , NET452 , NET46 , NET461 , NET462 , NET47 , NET471 , NET472 , NET48 NETFRAMEWORK , NET20 , NET35 , NET40 , NET45 , NET451 , NET452 , NET46 , NET461 , NET462 , NET47 , NET471 , NET472 , NET48 |
.NET Standard.NET Standard | NETSTANDARD 、NETSTANDARD1_0 、NETSTANDARD1_1 、NETSTANDARD1_2 、NETSTANDARD1_3 、NETSTANDARD1_4 、NETSTANDARD1_5 、NETSTANDARD1_6 、NETSTANDARD2_0 、NETSTANDARD2_1 NETSTANDARD , NETSTANDARD1_0 , NETSTANDARD1_1 , NETSTANDARD1_2 , NETSTANDARD1_3 , NETSTANDARD1_4 , NETSTANDARD1_5 , NETSTANDARD1_6 , NETSTANDARD2_0 , NETSTANDARD2_1 |
.NET Core.NET Core | NETCOREAPP , NETCOREAPP1_0 , NETCOREAPP1_1 , NETCOREAPP2_0 , NETCOREAPP2_1 , NETCOREAPP2_2 , NETCOREAPP3_0 , NETCOREAPP3_1 NETCOREAPP , NETCOREAPP1_0 , NETCOREAPP1_1 , NETCOREAPP2_0 , NETCOREAPP2_1 , NETCOREAPP2_2 , NETCOREAPP3_0 , NETCOREAPP3_1 |
非推奨のターゲット フレームワークDeprecated target frameworks
次のターゲット フレームワークは非推奨とされます。The following target frameworks are deprecated. これらのターゲット フレームワークをターゲットにするパッケージは、指定されている代替フレームワークに移行する必要があります。Packages targeting these target frameworks should migrate to the indicated replacements.
非推奨の TFMDeprecated TFM | ReplacementReplacement |
---|---|
aspnet50aspnet50 aspnetcore50aspnetcore50 dnxcore50dnxcore50 dnxdnx dnx45dnx45 dnx451dnx451 dnx452dnx452 |
netcoreappnetcoreapp |
dotnetdotnet dotnet50dotnet50 dotnet51dotnet51 dotnet52dotnet52 dotnet53dotnet53 dotnet54dotnet54 dotnet55dotnet55 dotnet56dotnet56 |
netstandardnetstandard |
netcore50netcore50 | uap10.0uap10.0 |
winwin | netcore45netcore45 |
win8win8 | netcore45netcore45 |
win81win81 | netcore451netcore451 |
win10win10 | uap10.0uap10.0 |
winrtwinrt | netcore45netcore45 |
関連項目See also
- パッケージ、メタパッケージ、フレームワークPackages, Metapackages and Frameworks
- クロス プラットフォーム ツールによるライブラリの開発Developing Libraries with Cross Platform Tools
- .NET Standard.NET Standard
- .NET Core バージョン管理.NET Core Versioning
- dotnet/standard GitHub リポジトリdotnet/standard GitHub repository
- NuGet Tools GitHub リポジトリNuGet Tools GitHub Repository
- .NET のフレームワーク プロファイルFramework Profiles in .NET
フィードバック
フィードバックを読み込んでいます...