[. NET object-oriented programming in depth] (8) understanding. NET Core
1, overview
. NET has been performing well on the Windows platform for over 14 years, but "cross-platform, open source" is its pain point, starting in 16. NET core will usher in the true meaning of. NET cross-platform and open source prologue.
. NET Core is an open-source, common development framework that supports cross-platform development and deployment on systems such as Window,macos,linux, and can be used in hardware devices, cloud services, and embedded/IoT scenarios.
the source of. NET core is on GitHub and is supported by Microsoft's official and community partners.
Here's a look at the similarities and differences between the two branches of the. NET Framework and. NET Core.
2,
NET Framework and. NET Core Architecture
a.NET Framework contains, Windows form,wpf,asp.net
b.net core contains, Uwp,asp.net core
C.xamarin, new. NET also includes a third part, Xamarin for building mobile apps, including iOS, OS X, Android, and more.
that's called. NET three carriage, below is the newest. NET Eco-system diagram:
As you can see, the. NET Framework and. NET core and Xamarin will be the three major parts of. NET now and in the future, and all three are independent of each other, but are based on the. NET Standard library.
3,net Framework and. NET Core features
. NET core has a significant improvement in performance and development efficiency compared to the previous. NET Framework. The key is for the first time. NET of the complete cross-platform capabilities of the underlying technology stack.
. NET core is based on cross-platform capabilities and does not migrate GUI-height-related APIs into. NET core, so it looks like Windows Forms or Windows Presentation Foundation (WPF) is not ported to. NET Core.
. NET Core supports console applications (console application) and Projects of class library type.
However, Microsoft uses. NET Core in its Universal Windows Platform (UWP) development platform and uses. NET Native technology to increase its performance to very close to native code speed.
ASP. NET core drives its managed Environment Kestrel Server in a console application to support the operation of an ASP. NET Core program.
A.. NET Framework
(1) The King Framework for Windows applications: the. NET framework is used to create Windows system-based applications, including Windows from, WPF, ASP. Development under the Windows Framework. The. NET framework remains strong and will continue to update the upgrade for some time to come.
(2) Development language choice: can choose c#,vb.net,f# and many other languages development.
B.. NET Core
(1) cross-platform. NET Core is the latest cross-platform framework that Microsoft has launched, with applications that can be created to run on Mac,linux. . NET Core supports UWP and ASP. CORE,UWP, Windows 10, universal Windows platform short. That is, the Windows Universal application platform that runs on a platform such as the win Mobile/surface (Windows tablet)/pc/xbox/hololens, which is different from the Exe app on the traditional PC, is also essential to a mobile-only app. It is not designed for one terminal, but it can be run on all WINDOWS10 devices.
(2) Open source. NET core belongs to the. NET Foundation and is officially supported by Microsoft. Using the MIT and Apache 2 Open source protocols, document protocols follow cc-by
(3) Compatibility: see the. NET core and. NET Framework based on the. NET Standard Library from the previous diagram. Therefore, compatible with. NET Framework,xamarin,mono.
(4) Flexible deployment mechanism: The first kind. Portable applications (Portable application) This deployment mechanism is similar to the traditional. NET Framework, as long as there is a. NET Core runtime on the target platform.
The second kind. Self-contained application (self-hosted application) as its name implies, this deployment mechanism packages the application and runtime together, even if the. NET Core runtime is not installed on the target platform, and the second way is not the same as. NET native. CoreCLR is still used, and. NET native uses Corert as the runtime, see Dotnet/corert for more information.
(5) Command line tool:. NET program all run scripts can be executed with command-line tools (Cmd,bash).
(6) Language selection: The programming languages supported in. NET Core 1.0 are only C # (F # and VB are temporarily not implemented)
4,.net Core Composition System
it says above. NET's Troika,. NET Framework,. NET core, XAMARIN, here's a look at the composition of. NET Core
such as, NET Core Composition System:
( 1) Runtime has two runtime,nativeruntime and CoreCLR implementations in. NET Core. Nativeruntime converts C # or vb.net code directly to native machine code. While CoreCLR is an open source JIT runtime, the code is compiled into intermediate language (IL) to convert the machine code at the end of the run.
( 2) Unified BCL base classlibrary is the base class, such as FileSystem, Console, XML operations, and so on.
( 3) Windows Store Appmodel & ASP. NET Core 1.0 provides a variety of touch-screen devices and ASP.N for developing Windows systems A set of base libraries for the ET program.
5,.net Core individual function modules
such as:
Application layer: The system composition of. NET Core, the top tier is the application layer, is the development of a framework set based on UI applications, including the ASP (for creating Web apps), and the UWP (for creating the Windows10 app).
Middle tier: The middle tier is a common library (COREFX): Implements the. NET standard library, which includes common system-level operations such as (file, network, etc.).
under Corefx is the runtime environment,. NET Core contains two runtimes (CoreCLR, Corert), and CoreCLR is a runtime based on the instant compiler program (Just in Time Compiler,jit). It uses a cross-platform, open-source compiler, Ryujit,
while Corert is run with an advance compiler (Ahead of Time compiler,aot), it can either use Ryujit to implement AOT compilation or use other AOT compilers. Because AOT compiles IL into machine code, it also has better start-up speed and energy saving on mobile devices.
Compiler: Finally mention an open source cross-platform source code compiler Roslyn, which differs from just two compilers, JIT and AOT compilers are primarily used to compile IL machine code, while Roslyn is C # or vb.net The code is compiled into a program intermediate language (intermediate Language,il).
This compiler is described below.
(1),. NET Core Roslyn Compilers
The Roslyn compiler is used to compile C # or vb.net code into an assembly (assembly), and its compilation process is a pipelined process with a total of 4 steps, as described in the procedure.
A. Parser (parsing)
parses the source code according to the syntax.
B. Declaration (statement)
to generate metadata for code (metadata), metadata is a collection of data tables that describe the data types and members defined in the current code, as well as the types and members of the references.
C. bind (BIND)
The generated IL code is bound together with the metadata that describes it, generating a managed module (managed module).
D. Emit (generated)
merges one or more managed modules into the Build assembly (assembly).
(2) RyuJIT compiler
in the program to run a certain method, the first need to convert the compiled IL to the machine code of the machine, and this task is given to the Ryujit. It is a new generation of JIT compilers that, for the first time, implemented the AMD64 architecture, Ryujit able to generate code faster than JIT64 (the previous generation compiler ) to improve the process sequence run efficiency (test detail link).
(3) CoreCLR & Corert
Both CoreCLR and Corert are. NET core runtime (runtime), which provides core functionality similar to the. NET Framework CLR (memory management, assembly loading, security, exceptions, thread management, and so on) that can be used by all languages that are intended for the runtime.
Unlike Corert and CoreCLR, Corert provides a set of AOT mechanisms that can compile. NET core programs into native code and run on the host machine without relying on. Net.
In addition to the two runtime most of the function code is shared, such as GC. The AOT optimization brings many benefits:
compiled into a single file containing all dependencies, including Corert, without the need to install the framework
Machine Code on startup, no machine code required and no JIT compiler to load
Other optimization compilers can be used, including LLILC, IL to CPP
Corert There are two ways to generate machine code, the first use is to directly compile IL into machine code, by default, RyuJIT as an AOT compiler to compile IL into machine code, another way is to compile C # code into C + + code, and then call the corresponding platform C + + Compiler optimizations are compiled into machine code.
compiling machine code using RyuJIT
--native--ilcpath <repo_root>\bin\product\windows_nt.x64.debug\packaging\publish1
compile to generate C + + code
--native--cpp--ilcpath <repo_root>--CPPCOMPILERFLAGS/MTD
Corert also has shortcomings, it needs to compile for different platforms once; but it allows engineers to not publish to platforms they do not want to support (such as a game that only supports the desktop and does not support mobile phones).
(4) Corefx (. NET Core Libraries)
Corefx mainly contains several public libraries, such as System.Collections, System.IO, System.Xml, etc. Corefx is the implementation of the. NET Standard library, and the same. NET Framework 4.6.3 is also based on the. NET Standard library implementation. They are currently based on the. NET standard Library1.6 version, as detailed in the following table:
6.. NET Core code Development, deployment, and operational procedures
you can see that using JIT compiling and using AOT to compile source code and run programs are two different processes.
If you are using the JIT compiler to deploy a program with only the assemblies of the program packaged as IL, the compiler compiles the IL to the target machine code (Native code) before the method executes the first time, and AOT compilation compiles the source code directly to the target machine code at compile time.
The AOT compiles the source code into machine code and has the following features:
(1) Replace the reflection with static code, for example, if a value type is not overridden by the Equals method of Valuetype.equals, the default condition is equal, Filedinfo are found using reflection to determine whether the type is equal, and then compare value for equality. In AOT compilation, you can only compare value for equality because it replaces reflection.
(2) Dependent third-party class libraries and. NET libraries are packaged into the final compiled program.
(3) The packaged program runs on a lite version of the runtime (Corert) primarily contains the garbage collector, and the runtime is packaged in an app file.
(4) Although the compilation will replace the reflection code, but in the event of dynamic reflection code can not do, when the runtime in case of dynamic reflection calls will not find the corresponding metadata and implementation of the exception thrown. The workaround is to configure the run-time Directive file (runtime, Directive file) to specify the assembly to use before compiling.
7, Summary
the main introduction. NET Troika the. NET Framework,. NET core, and xamarin,.net framework are the king's frameworks for developing Windows-based platforms, while. NET Core's cross-platform features, open source, and flexible deployment mechanisms will be. NET's future. The following describes the composition of. NET core, the main functional modules of. NET Core: The application layer, the middle tier, the compiler. Finally, the development, deployment, and running processes of. NET core are briefly described.
(Disclaimer: This article refers to some information and blog, if there is infringement, please inform, the first time to delete, change.) )
==============================================================================================
Back to Catalog
< If it is helpful to you, please remember to click on the recommendation Oh, if there is have no understanding or error the Place , please communicate more >
< REPRINT statement: Technology needs to share the spirit, welcome to reprint the article in this blog, but please specify copyright and url>
Software Management and . NET Technology Exchange Group: 467189533
==============================================================================================
[. NET object-oriented programming in depth] (8) understanding. NET Core