Target frameworks
https://docs.microsoft.com/en-us/dotnet/standard/frameworks
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. You specify the target framework in your project file using Target Framework Monikers (TFMs).
An app or library can target a version of .NET Standard. .NET Standard versions represent standardized sets of APIs across all .NET implementations. 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.
An app or library can also target a specific .NET implementation to gain access to implementation-specific APIs. 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.
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).
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. A metapackage is a NuGet package that has no content of its own but is a list of dependencies (other packages). 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
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. A Target Framework Moniker (TFM) is a standardized token format for specifying the target framework of a .NET app or library.
| Target Framework | Latest Stable Version |
Target Framework Moniker (TFM) | Implemented .NET Standard Version |
|---|---|---|---|
| .NET Standard | 2.0 | netstandard2.0 | N/A |
| .NET Core Application | 2.0 | netcoreapp2.0 | 2.0 |
| .NET Framework | 4.7.2 | net472 | 2.0 |
Supported target framework versions
A target framework is typically referenced by a TFM. The following table shows the target frameworks supported by the .NET Core SDK and the NuGet client. Equivalents are shown within brackets. For example, win81 is an equivalent TFM to netcore451.
| Target Framework | TFM |
|---|---|
| .NET Standard | netstandard1.0 netstandard1.1 netstandard1.2 netstandard1.3 netstandard1.4 netstandard1.5 netstandard1.6 netstandard2.0 |
| .NET Core | netcoreapp1.0 netcoreapp1.1 netcoreapp2.0 netcoreapp2.1 |
| .NET Framework | net11 net20 net35 net40 net403 net45 net451 net452 net46 net461 net462 net47 net471 net472 |
| Windows Store | netcore [netcore45] netcore45 [win] [win8] netcore451 [win81] |
| .NET Micro Framework | netmf |
| Silverlight | sl4 sl5 |
| Windows Phone | wp [wp7] wp7 wp75 wp8 wp81 wpa81 |
| Universal Windows Platform | uap [uap10.0] uap10.0 [win10] [netcore50] |
How to specify target frameworks
Target frameworks are specified in your project file. When a single target framework is specified, use the TargetFramework element. The following console app project file demonstrates how to target .NET Core 2.0:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
</Project>
When you specify multiple target frameworks, you may conditionally reference assemblies for each target framework. In your code, you can conditionally compile against those assemblies by using preprocessor symbols with if-then-else logic.
The following library project file targets APIs of .NET Standard (netstandard1.4) and APIs of the .NET Framework (net40 and net45). Use the plural TargetFrameworks element with multiple target frameworks. 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
}
}
The build system is aware of preprocessor symbols representing the target frameworks shown in the Supported target framework versions table. 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).
The complete list of preprocessor symbols for .NET Core target frameworks is:
| Target Frameworks | Symbols |
|---|---|
| .NET Framework | NET20, NET35, NET40, NET45, NET451, NET452, NET46, NET461, NET462, NET47, NET471, NET472 |
| .NET Standard | NETSTANDARD1_0, NETSTANDARD1_1, NETSTANDARD1_2, NETSTANDARD1_3, NETSTANDARD1_4, NETSTANDARD1_5, NETSTANDARD1_6, NETSTANDARD2_0 |
| .NET Core | NETCOREAPP1_0, NETCOREAPP1_1, NETCOREAPP2_0, NETCOREAPP2_1 |
Deprecated target frameworks
The following target frameworks are deprecated. Packages targeting these target frameworks should migrate to the indicated replacements.
| Deprecated TFM | Replacement |
|---|---|
| aspnet50 aspnetcore50 dnxcore50 dnx dnx45 dnx451 dnx452 |
netcoreapp |
| dotnet dotnet50 dotnet51 dotnet52 dotnet53 dotnet54 dotnet55 dotnet56 |
netstandard |
| netcore50 | uap10.0 |
| win | netcore45 |
| win8 | netcore45 |
| win81 | netcore451 |
| win10 | uap10.0 |
| winrt | netcore45 |
See also
Packages, Metapackages and Frameworks
Developing Libraries with Cross Platform Tools
.NET Standard
.NET Core Versioning
dotnet/standard GitHub repository
NuGet Tools GitHub Repository
Framework Profiles in .NET
Target frameworks的更多相关文章
- 理解 .NET Platform Standard
相关博文:ASP.NET 5 Target framework dnx451 and dnxcore50 .NET Platform Standard:https://github.com/dotne ...
- NET Platform Standard
NET Platform Standard 相关博文:ASP.NET 5 Target framework dnx451 and dnxcore50 .NET Platform Standard:ht ...
- visual studio code .net 开发
Visual Studio确实是相当好用,各种简化操作什么的简直不要太舒服.但其容量太大,有时不是很方便,所以今天简单介绍一下另一个工具--Visual Studio Code. 虽然相比于老大哥Vi ...
- Multi-Targeting and Porting a .NET Library to .NET Core 2.0
Creating a new .NET Standard Project The first step for moving this library is to create a new .NET ...
- .NET Core launch.json 简介
1.环境 Windows,.NET Core 2.0,VS Code dotnet> dotnet new console -o myApp 2.launch.json配置文件 { // Use ...
- Ubuntu16.10下使用VSCode开发.netcore
按照通常的套路,首先创建一个空白的解决方案,需要用到.netcore sdk命令: dotnet new sln -o dotnetcore_tutrorial 这个时候可以看到在目标目录下生成了一个 ...
- Sharing Code Between Silverlight and Win8 app metro
这里讲得很详细了: Sharing Code between Windows Phone 8 and Windows 8 Applications http://msdn.microsoft.com/ ...
- 如何移植.NET Framework项目至.NET Core?
公司的项目一直采用.NET框架来开发Web项目.目前基础类库均为.NET Framework 4.6.2版本.Caching, Logging,DependencyInjection,Configur ...
- C#设计模式总结 C#设计模式(22)——访问者模式(Vistor Pattern) C#设计模式总结 .NET Core launch.json 简介 利用Bootstrap Paginator插件和knockout.js完成分页功能 图片在线裁剪和图片上传总结 循序渐进学.Net Core Web Api开发系列【2】:利用Swagger调试WebApi
C#设计模式总结 一. 设计原则 使用设计模式的根本原因是适应变化,提高代码复用率,使软件更具有可维护性和可扩展性.并且,在进行设计的时候,也需要遵循以下几个原则:单一职责原则.开放封闭原则.里氏代替 ...
随机推荐
- 转:【微信小程序】实现锚点定位楼层跳跃的实例
微信小程序实现楼层锚点跳跃,点击不同的锚点进行位置跳跃: 利用:scroll-into-view 来实现: 效果图: wxml: <scroll-view class="cont ...
- OAuth 授权timestamp refused问题
400 timestamp_refused /oauth/request_token 两台机器161.155 两机器代码完全一致,但155部署时,启动需要OAu ...
- operator new 和 operator delete 实现一个简单内存泄漏跟踪器
先来说下实现思路:可以实现一个Trace类,调用 operator new 的时候就将指向分配内存的指针.当前文件.当前行等信息添加进Trace 成员map容器内,在调用operator delete ...
- 类声明、类作用域、前向声明、this指针、嵌套类、PIMPL 技法 等
一.类声明 //类是一种用户自定义类型,声明形式: class 类名称 { public: 公有成员(外部接口) private: 私有 ...
- Docker中images中none的镜像删除
docker build 或是 pull 命令就会产生临时镜像.如果我们用dockerfile创建一个helloworld镜像后,因为版本更新需要重新创建,那么以前那个版本的镜像就会 成为临时镜像.这 ...
- shell 基础语法
shell 基础语法 =============================================== 推荐:http://c.biancheng.net/cpp/shell/ ==== ...
- Redis C#入门
redis-cli.exe 为客户端 redis-server.exe 为服务端 进行操作都是在客户端上操作,先随便添加一组 key value试一下: 再输入Get "键"名称, ...
- 云中的机器学习:FPGA 上的深度神经网络
人工智能正在经历一场变革,这要得益于机器学习的快速进步.在机器学习领域,人们正对一类名为“深度学习”算法产生浓厚的兴趣,因为这类算法具有出色的大数据集性能.在深度学习中,机器可以在监督或不受监督的方式 ...
- PL/SQL developer连接oracle出现“ORA-12154:TNS:could not resolve the connect identifier specified”问题的解决
转载请注明出处:http://blog.csdn.net/dongdong9223/article/details/50728536 本文出自[我是干勾鱼的博客] 使用PL/SQL developer ...
- 常用vim编辑器命令行
按ESC键 跳到命令模式,然后: :w 保存文件但不退出vi:w file 将修改另外保存到file中,不退出vi:w! 强制保存,不推出vi:wq 保存文件并退出vi:wq! 强制保存文件,并退出v ...