理解 .NET Platform Standard
相关博文:ASP.NET 5 Target framework dnx451 and dnxcore50
.NET Platform Standard:https://github.com/dotnet/corefx/blob/master/Documentation/architecture/net-platform-standard.md
.NET Platform Standard 是什么?直译过来就是 .NET 平台规范或标准,它的目的就是使 .NET 各个平台之间更加统一和规范,在之前的 .NET Core RC2 发布文章中提到了 .NET Standard Library,它其实就是 .NET Platform Standard 的体现之一,.NET Standard Library 现在有一个对应程序包NETStandard.Library
,它的作用是兼容各个 .NET Platform,这个后面有进行说明,现在只是一个临时方案,以后微软慢慢会把相关的程序包(比如基础类库等),按照 .NET Standard Library 的标准进行开发和发布。
.NET Platform Standard 列表:
Target Platform Name | Alias | |||||||
---|---|---|---|---|---|---|---|---|
.NET Platform Standard | netstandard | 1.0 | 1.1 | 1.2 | 1.3 | 1.4 | 1.5 | 1.6 |
.NET Core | netcoreapp | → | → | → | → | → | → | 1.0 |
.NET Framework | net | → | → | → | → | → | → | 4.6.3 |
→ | → | → | → | → | 4.6.2 | |||
→ | → | → | → | 4.6.1 | ||||
→ | → | → | 4.6 | |||||
→ | → | 4.5.2 | ||||||
→ | → | 4.5.1 | ||||||
→ | 4.5 | |||||||
Universal Windows Platform | uap | → | → | → | → | 10.0 | ||
Windows | win | → | → | 8.1 | ||||
→ | 8.0 | |||||||
Windows Phone | wpa | → | → | 8.1 | ||||
Windows Phone Silverlight | wp | 8.1 | ||||||
8.0 | ||||||||
Mono/Xamarin Platforms | → | → | → | → | → | → | * | |
Mono | → | → | * |
上面这些都是概念,我们在 ASP.NET Core 1.0 RC2 项目开发中,如何应用和体现呢?其实就是我们在project.json
中配置的frameworks
节点,我们先看一段配置(来自 Microsoft.EntityFrameworkCore/project.json):
"frameworks": {
"net451": {
"frameworkAssemblies": {
"System.ComponentModel.DataAnnotations": "",
"System.Runtime": {
"type": "build"
}
}
},
"netstandard1.3": {
"imports": [
"portable-net452+win81"
],
"dependencies": {
"System.Collections.Concurrent": "4.0.12-*",
"System.ComponentModel.Annotations": "4.1.0-*",
"System.Linq.Queryable": "4.0.1-*",
"System.ObjectModel": "4.0.12-*",
"System.Reflection.Extensions": "4.0.1-*",
"System.Reflection.TypeExtensions": "4.1.0-*"
}
},
"netcore50": {
"dependencies": {
"Microsoft.NETCore.Platforms": {
"type": "build",
"version": "1.0.1-*"
},
"System.Collections.Concurrent": "4.0.10",
"System.ComponentModel.Annotations": "4.0.10",
"System.Linq.Queryable": "4.0.0",
"System.ObjectModel": "4.0.10",
"System.Reflection.Extensions": "4.0.0",
"System.Reflection.TypeExtensions": "4.0.0",
"System.Runtime": {
"type": "build",
"version": "4.0.20"
},
"System.Dynamic.Runtime": {
"type": "build",
"version": "4.0.10"
},
"System.Runtime.WindowsRuntime": {
"type": "build",
"version": "4.0.10"
},
"System.Runtime.Extensions": {
"type": "build",
"version": "4.0.10"
}
}
}
}
可以看到frameworks
配置了net451
、netstandard1.3
和netcore50
,这些是什么意思?从上面的 .NET Platform Standard 列表中,我们可以得到一些信息,但还是有些不太明白,我们看一下相关解释(来自 Project.json definition dnx451 vs .dotnet (4.51)):
dnxcore50
: DNX SDK running on CoreCLR/CoreFx (deprecated, usenetcoreapp1.0
instead).dnx451
: DNX SDK running on .Net 4.5.1 (Desktop CLR / Full BCL and FCL) (deprecated, usenet451
instead).net46
: .Net Framework 4.6 SDK running on Desktop CLR / Full BCL and FCL.uap10.0
: UWP Windows 10 SDK running on .Net Native/CoreFx.netcoreapp1.0
: .NET Core 1.0 SDK running on CoreCLR/CoreFx.netstandard1.5
: (RC2,dotnet
before) any pure IL code which declares its dependencies (System.Runtime (based) libraries instead of a PCL contracts). Framework dependencies are available for .Net 4.5.x onwards, .NET Core or UWP (System.Runtime based library set in different versions). As with RC2dotnet
is deprecated, usenetstandard
instead.
先看dnxcore50
的解释,DNX SDK 是什么?它其实是一种命令或工具,指向你的程序集使用的哪种目标环境,CoreCLR/CoreFx 就是说,程序集跑在 CoreCLR/CoreFx 上,dnxcore50
现在已经被弃用了,被 netcoreapp1.0
所替代,netstandard1.5
是一种新的平台规范,使用它必须引用NETStandard.Library
程序包,否则System
所有相关命名空间都找不到。
简单来说,frameworks
所配置的就是你程序集的运行环境或平台,如果配置了多个,就表示程序集可以跑在多个平台上,比如,上面Microsoft.EntityFrameworkCore
配置了net451
、netstandard1.3
和netcore50
,也就是说Microsoft.EntityFrameworkCore
可以被这三种平台的程序集引用,比如你的程序集frameworks
中只配置了net451
,照样可以引用Microsoft.EntityFrameworkCore
程序集,只不过只能在 Windows 上运行,不能跨平台而已,一个程序集不同平台的代码写法:
#if DNX451
//Code here for dnx451
#elif DNXCORE50
//code here for dnxcore50
#endif
imports
的解释是(来自 Frameworks and imports sections in project.json: what are they?):imports
is a way to use packages that were not designed for that framework. Basically you tell it "Use those targets even though they don't seem to be supported. I know what I'm doing". 简单来说,就是兼容本程序集配置平台所不支持的平台,有点绕,我们做一个测试就清楚了:
如上图的配置,为什么frameworks
配置了netcoreapp1.0
会出现错误?因为我们引用的Microsoft.EntityFrameworkCore
程序包并不完全支持netcoreapp1.0
平台,所以我们需要在netcoreapp1.0
下增加"imports": ["net451"]
配置,其作用就是使之兼容,当然现在只是兼容平台的配置,以后完善之后,这个配置会去掉的。
imports
的一段配置:
"netcoreapp1.0": {
"imports": [
"net461",
"portable-net45+win81"
]
}
首先,imports
可以配置多个节点,portable-net45+win81
是什么意思?portable 的意思是便携式的,在之前的博文中有提及,意思就是自身发布不携带依赖的程序包,而是使用系统中安装配置的,net45
就是上面说的frameworks
配置,win81
是系统平台的意思,但不只是特指 Windows 8.1 系统。
Platform | NuGet identifier |
---|---|
.NET Framework 2.0 - 4.6 | net20 - net46 |
.NET Core | netcoreapp |
.NET Micro Framework | netmf |
Windows 8 | win8, netcore45 |
Windows 8.1 | win8, netcore451 |
Windows Phone Silverlight (8, 8.1) | wp8, wp81 |
Windows Phone 8.1 | wpa8.1 |
Universal Windows Platform 10 | uap10, netcore50 |
Silverlight 4, 5 | sl4, sl5 |
MonoAndroid | monoandroid |
MonoTouch | monotouch |
MonoMac | monomac |
Xamarin iOS | xamarinios |
Xamarin PlayStation 3 | xamarinpsthree |
Xamarin PlayStation 4 | xamarinpsfour |
Xamarin PlayStation Vita | xamarinpsvita |
Xamarin Watch OS | xamarinwatchos |
Xamarin TV OS | xamarintvos |
Xamarin Xbox 360 | xamarinxboxthreesixty |
Xamarin Xbox One | xamarinxboxone |
最后,再做一个测试,这个我们一般在 ASP.NET 5 Core 1.0 RC1 升级到 RC2 中会遇到的,两个程序集:
CNBlogs.Ad.Infrastructure.Interfaces
CNBlogs.Ad.Infrastructure
: 依赖于CNBlogs.Ad.Infrastructure.Interfaces
CNBlogs.Ad.Infrastructure.Interfaces
的project.json
配置:
{
"version": "1.0.0-*",
"description": "CNBlogs.Ad.Infrastructure.Interfaces Class Library",
"authors": [ "xishuai" ],
"frameworks": {
"netcoreapp1.0": {
"imports": [
"net451"
]
},
"net451": { }
},
"dependencies": {
"Microsoft.EntityFrameworkCore": "1.0.0-rc2-final",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final"
}
}
CNBlogs.Ad.Infrastructure
的project.json
配置:
{
"version": "1.0.0-*",
"description": "CNBlogs.Ad.Infrastructure Class Library",
"authors": [ "xishuai" ],
"frameworks": {
"netcoreapp1.0": {
"imports": [
"net451"
]
},
"net451": { }
},
"dependencies": {
"CNBlogs.Ad.Infrastructure.Interfaces": "1.0.0-*",
"Microsoft.EntityFrameworkCore": "1.0.0-rc2-final",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final"
}
}
几种测试情况:
CNBlogs.Ad.Infrastructure.Interfaces
中的netcoreapp1.0
去除"imports": ["net451"]
配置:出现错误,上面有过分析,因为Microsoft.EntityFrameworkCore
并不完全支持netcoreapp1.0
。CNBlogs.Ad.Infrastructure.Interfaces
去除netcoreapp1.0
配置:出现错误,因为CNBlogs.Ad.Infrastructure
配置了netcoreapp1.0
,而引用的CNBlogs.Ad.Infrastructure.Interfaces
却支持net451
。CNBlogs.Ad.Infrastructure.Interfaces
去除net451
配置:出现错误,同上,因为CNBlogs.Ad.Infrastructure
配置了net451
,而引用的CNBlogs.Ad.Infrastructure.Interfaces
却支持netcoreapp1.0
。CNBlogs.Ad.Infrastructure
去除netcoreapp1.0
配置:成功,因为依赖的CNBlogs.Ad.Infrastructure
支持net451
。CNBlogs.Ad.Infrastructure
去除net451
配置:出现成功,同上,因为依赖的CNBlogs.Ad.Infrastructure
支持netcoreapp1.0
。
综合上面的测试,简单来说,就是程序包的运行平台或环境取决于底层的引用,底层的引用指的是你自己项目中的程序包,而不是基础类库和微软开发的程序包,因为它们都支持多平台,比如上面的Microsoft.EntityFrameworkCore
程序包。
另外,如果你的程序包frameworks
配置的是net451
,它其实和 .NET Core 没多大关系了,因为它使用的是 .NET Framework 和 Desktop CLR,而不是 CoreCLR 和 CoreFx,即使你项目中使用的是 .NET Core RC2 的程序包。
参考资料:
- Project.json definition dnx451 vs .dotnet (4.51)
- Target Frameworks
- Project.json Frameworks
- What frameworks are available in ASP.NET Core (ASP.NET 5) applications?
- .NET Platform Standard
- Frameworks and imports sections in project.json: what are they?
- All about httpRuntime targetFramework
- Project.json Usage
理解 .NET Platform Standard的更多相关文章
- Java Platform Standard Edition 8 Documentation
下面这个图挺有用的,收藏一下. Oracle has two products that implement Java Platform Standard Edition (Java SE) 8: J ...
- NET Platform Standard
NET Platform Standard 相关博文:ASP.NET 5 Target framework dnx451 and dnxcore50 .NET Platform Standard:ht ...
- ASP.NET Core 1.0 开发记录
官方资料: https://github.com/dotnet/core https://docs.microsoft.com/en-us/aspnet/core https://docs.micro ...
- 关于ASP.Net的一些概念 转载
①理解 .NET Platform Standard 作者:田园里的蟋蟀 http://www.cnblogs.com/xishuai/archive/2016/05/24/understand-do ...
- Java多线程 -- 深入理解JMM(Java内存模型) --(五)锁
锁的释放-获取建立的happens before 关系 锁是Java并发编程中最重要的同步机制.锁除了让临界区互斥执行外,还可以让释放锁的线程向获取同一个锁的线程发送消息. 下面是锁释放-获取的示例代 ...
- ionic cordova platform --help
ionic platform add android 给我报这个问题,不理解 The platform command has been renamed. To find out more, run: ...
- 深入理解JMM(Java内存模型) --(五)锁
锁的释放-获取建立的happens before 关系 锁是Java并发编程中最重要的同步机制.锁除了让临界区互斥执行外,还可以让释放锁的线程向获取同一个锁的线程发送消息. 下面是锁释放-获取的示例代 ...
- Linux驱动中的platform总线分析
copy from :https://blog.csdn.net/fml1997/article/details/77622860 概述 从Linux2.6内核起,引入一套新的驱动管理和注册机制:pl ...
- .NET Core系列 : 2 、project.json 这葫芦里卖的什么药
.NET Core系列 : 1..NET Core 环境搭建和命令行CLI入门 介绍了.NET Core环境,本文介绍.NET Core中最重要的一个配置文件project.json的相关内容.我们可 ...
随机推荐
- 关于 Chrome 浏览器中 onresize 事件的 Bug
我在写插件时用到了 onresize 事件,在反复地测试后发现该事件在 Chrome 及 Opera(内核基本与 Chrome 相同,以下统称 Chrome)浏览器打开时就会执行,这种情况也许不能算作 ...
- 前端学HTTP之字符集
前面的话 HTTP报文中可以承载以任何语言表示的内容,就像它能承载图像.影片或任何类型的媒体那样.对HTTP来说,实体主体只是二进制信息的容器而已.为了支持国际性内容,服务器需要告知客户端每个文档的字 ...
- Linux上如何查看物理CPU个数,核数,线程数
首先,看看什么是超线程概念 超线程技术就是利用特殊的硬件指令,把两个逻辑内核模拟成两个物理芯片,让单个处理器都能使用线程级并行计算,进而兼容多线程操作系统和软件,减少了CPU的闲置时间,提高的CPU的 ...
- web api接口同步和异步的问题
一般来说,如果一个api 接口带上Task和 async 一般就算得上是异步api接口了. 如果我想使用异步api接口,一般的动机是我在我的方法里面可能使用Task.Run 进行异步的去处理一个耗时的 ...
- PHP 设计模式概述
一.设计模式(Design pattern)是什么? 设计模式是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结.使用设计模式是为了可重用代码.让代码更容易被他人理解.保证代码可靠性. ...
- iOS从零开始学习直播之1.播放
对于直播来说,客户端主要做两件事情,推流和播放.今天先讲播放. 播放流程 1.拉流:服务器已有直播内容,从指定地址进行拉取的过程.其实就是向服务器请求数据. 2.解码:对视屏数据进行解压缩. 3. ...
- NodeJS使用mysql
1.环境准备 手动添加数据库依赖: 在package.json的dependencies中新增, "mysql" : "latest", { "nam ...
- SQL SERVER导入数据到ORACLE的方法总结
我们偶尔会有将数据从SQL SERVER导入到ORACLE当中的这种需求,那么这种跨数据库导数有那些方法呢?这些方法又有那些利弊呢? 下面比较肤浅的总结了一些可行的方法. 1:生成SQL脚本然后去OR ...
- 项目自动化建构工具gradle 入门1——输出helloWorld
先来一个简单的例子,4个步骤: 1.进入D:\work\gradle\java 目录 ,您电脑没这目录? 那辛苦自己一级一级建立起来吧 新建文件build.gradle,文件内容是: apply p ...
- 用ffmpeg快速剪切和合并视频
如果直接找视频剪切和合并视频的软件,通常出来的都是大的视频编辑软件或者是有图形界面的剪切软件,大型一点的功能太多安装麻烦,小型一点的功能可能不齐全. 只是简单的剪切或者一下合并一下,还是ffmpeg这 ...