.Net泛指Microsoft公司的一种技术
.Net泛指一个平台
.Net泛指一个标准:.Net Standard
.Net泛指一个具体框架实现:.Net Framework、Mono、.Net Core
.NET与其他软件间的关系
2002年发布第一个版本
2016年发布.NET Core 1.0
简要总结:
.NET Core 3.0在2019年九月发布
.NET Core 3.1在2019年十一月发布,这是一个Long Term Support版本
.NET 5.0在2020年发布,这是一个General Availability版本
.NET 6.0在2021年十一月发布,这是一个Long Term Support版本
注意:偶数版本号表示稳定版本
.NET Core版本发布节点
.NET框架重写(rewrite),将.NET框架 变为真正的跨平台框架
.NET Core 将.NET与Windows的紧密联系脱钩
.NET Core框架 和 .NET Framework框架 在.NET 5合并
跨平台支持,支持跨平台开发、部署 (各软件工具都支持,不算啥特点)
性能 优于 .NET 4.x Framework (这不废话嘛,重写了原有的框架的嘛)
支持独立部署,可以自包含runtime (这个必须赞,可以自包含打包框架发布)
命令行支持程度 优于 .NET Framework (毕竟跨平台的嘛)
基本上 兼容 .NET 4.x Framework (重写向后兼容)
支持容器化部署 (这个必须有,现在必须有)
优点:
强大的基础类库BCL
支持多种语言,语言只要符合规范,可以互相操作
部署简单
缺点:
必须要.NET插件才能运行程序(使用.NET Core自包含部署不存在)
.NET版本存在不兼容问题(使用.NET Core自包含部署不存在)
三大主流平台都支持,没啥好说的
主要是看看支持的最低的系统的最低版本
统一了所有.NET基类库(Unified .NET with Single Base Class Library)
Previously, Xamarin apps (mobile apps) were based on the Mono BCL
but this has now moved into .NET 5 with improved compatibility as an outcome
多平台本地支持(Multi-Platform Native Apps)
A single project will be able to target multiple platforms
If you use a UI element
.NET will handle this appearing as a control native to the platform
云原生(Cloud Native)
Current .NET Code will certainly run in the cloud
but further steps will be taken towards labeling .NET a cloud-native framework
This includes a reduced footprint for easier use in containers and single file executables
so you don't need the .NET runtime to be installed
and aligning the cloud story and the local developer experience
so they are at feature parity
新增Blazor Web程序集(Blazor WebAssembly)
.NET Core 3.1 introduced Blazor apps that were rendered server-side
With .NET 5, they can be rendered client-side, enabling offline and standalone apps
The goal is that the code is close to identical
so it will be easy to switch from one hosting model to the other
多平台Web程序(Multi-Platform Web Apps)
Blazor apps was originally conceived as
a vehicle for web apps and works great in a browser
The goal is that this will work equally great for a mobile device
or a native desktop application
其他功能持续改进(Continuous Improvements)
Faster algorithms in the BCL
container support in the runtime
support for HTTP3, and other tweaks
Common Language Runtime ,CoreCLR (语言运行时)
Base Class Libraries ,BCL,CoreFX (类库)
Language compilers ,Roslyn (语言编译器)
.NET = 运行时(CLR) + 类库(BCL)
CLR(Command Language Runtime,公共语言运行时)
BCL(Base Class Library,基础类库)也叫FCL(Framework Class Library)
注意:.NET Core 3 是 .NET Core 2.2 和 .NET Framework的继承
CIL是微软.NET平台上衍生出的一门中间语言
.NET平台上的各种高级语言(如C#,VB,F#)的编译器会将各自的代码转化为CIL
C#源码最终被 编译器 编译 成 CIL
程序集的主要内容就是:CIL(Common Intermediate Language,公共中间语言)
程序集的外在文件类型:可执行的文件(.exe)、库(.dll)
使用CIL的优点:
语言优势:可以使用自己喜欢的语言,可以发挥各种语言的优势
平台优势:实现一次编写多平台运行,不同的语言的类库可以相互调用
使用CIL的缺点:
依赖.NET 运行时、效率不如编译语言效率高
程序集包含内容:
程序集中的可执行代码只在需要的时候由JIT编译器即时编译
然后就会被缓存起来以备在后来的程序中执行
一旦CIL被编译成本机代码,CLR就会在该代码运行的时候管理它,比如像内存管理、异常管理
托管代码 和 非托管代码 概念:
被CLR管理的代码称为 托管代码(managed code)
不被CLR管理的代码称为 非托管代码(unmanaged code)
可以使用Ngen工具,在客户机器上把提前把程序集转换为当前机器的本机代码,免除以后的JIT编译,以提高运行速度
CLR(Command Language Runtime,公共语言运行时)
注意:在.NET中叫CLR,在.NET Core中叫CoreCLR
作用:负责托管程序的执行
CLR(Common Language Runtime)包含内容:
CLR主要功能:
Language interoperability: Interoperability between different source languages. This is possible because the language compilers translate each source language to the same intermediate language (CIL).
Type safety: Checks for conversion between types, ensuring that only conversions between compatible types will occur. This helps prevent the occurrence of buffer overruns, a leading cause of security vulnerabilities.
Code access security: Certification that the assembly developer’s code has permission to execute on the computer.
Garbage collection: Memory management that automatically de-allocates memory previously allocated by the runtime.
Platform portability: Support for potentially running the same assembly on a variety of operating systems. One obvious restriction is that no platform-dependent libraries are used; therefore, platform-dependent idiosyncrasies need to be worked out separately.
Base Class Library (BCL): Provides a foundation of code that developers can depend on (in all .NET frameworks) so that they do not have to develop the code themselves.
公共语言基础结构(Common Language Infrastructure,CLI)
The Virtual Execution System
The Common Intermediate Language
The Common Type System
The Common Language Specification
Metadata
The framework
公共类型系统(Common Type System)
.Net支持的所有类型和编程结构描述
公共类型系统是一种规范,描述CLR支持的数据类型和编程结构,以及元数据的表示
作用在于可以实现CLR的一种规范
CLS(Common Language Specification,公共语言规范)
每种语言都用各自不同的特性,为了能让各种语言都可以在.NET上互相调用和协作
每种语言必须遵守一个共同的标准,CLI就是这种标准
公共语言规范是公共类型系统的一个子集,也是一种规范
作用是可以让各种语言可以互相操作和共享
.Net中CTS的子集,支持所有.Net上的编程语言
attribute at the bottom of this file and set its value to true
The location for GAC is “C:\Windows\assembly”
BCL(Base Class Library)公共基础类库
基本的类型定义、文件操作、序列化等
各种类相互组合又可以组成一定的框架,比如:
在程序集中设置
目前.NET有四种官方支持的实现:
.NET Core: 面向跨平台(cross-platform)应用 和 新应用(new apps)
.NET Framework: 面向遗留项目(legacy apps)
Xamarin: 面向移动应用(mobile apps)
UWP 面向Windows 商店应用
为了编写一个代码可以在多种实现上都可以使用,所以指定了一个通用的标准
.NET Standard标准不是一个实现,只是一个标准规定,规定了需要实现那些API
.NET Standard标准版本越高,可使用的 API 就越多
.NET Standard标准版本越低,可实现它的平台就越多
使用.NET Standard标准编写的代码
可以在多个.NET平台(.Net Framework、.Net Core、Xamarin)上运行
在项目配置文件.csproj中添加
该程序集不包含代码实现,只用于将具体的操作转发到其他具体的程序集
实现跨多个.Net实现平台运行托管代码
框架与C#语言的版本(Framework and C# Language Versions)
在创建项目的时候,选择的 框架版本 会自动对应着 C#语言的版本
.NET Core 3.x 和.NET Standard 2.1 默认使用C# 8
.NET Core 2.x、.NET Framework、.NET Standard 2.0默认使用 C# 7.3
.NET Portability Analyzer
使用该工具可以快速分析代码的各执行平台(.NET、.NET Core、Mono等)的兼容性
Visual Studio扩展下载
官方文档
基于.NET平台的 框架 和 功能
ILSpy
Windows系统 %ProgramFiles%\dotnet
Linux系统 /usr/bin/dotnet
handles memory allocation and de-allocation
type checking
interoperability with other languages
cross-platform execution
support for programming metadata
如果没有安装成功,翻一翻.NET Core官方文档
几乎所有.NET的功能都是通过大量托管类型来实现的
这些类型被组织成分层的名称空间(hierarchical namespaces)
并打包成一组程序集,这些程序集与CLR一起构成.NET核心平台
最基础最核心的类型都放在System命名空间中
比如:
built-in types、the Exception base class
Enum、Array、Delegate base classes
Nullable、Type、DateTime、TimeSpan、Guid
Math、Random、Convert、BitConverter
IFormattable、IComparable、IDisposable
比如:StringBuilder类型
主要是基于list-和dictionary-的集合
主要命名空间
主要命名空间:
主要命名空间:
主要命名空间:
主要命名空间:
主要命名空间:
主要命名空间:
主要命名空间:
主要命名空间:
System
主要命名空间:
主要命名空间:
主要命名空间:
The C# compiler itself is written in C#