New knowledge of. NET Core (reprint)

Source: Internet
Author: User
Tags dotnet

New understanding of. NET Core 

Cnblogs.com/yubinfeng/p/6626694.html

I. 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.

. NET open source projects:https://github.com/dotnet (including Standard, COREFX (. Net library), CORECLR (net Core runtime), Roslyn (Roslyn Compiler (C # and Visual Basic) and language tools for Visual Studio, CLI (command line interface and tools), Orleans, and some documentation including: Docs, DOCFX, etc.)

Ii.. NET Framework and. NET Core Architecture

    1. The. NET Framework contains, Windows form,wpf,asp.net

    2. . NET core contains, Uwp,asp.net core

    3. . 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.

Iii.. 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-highly-related APIs into. NET core, so Windows Forms or Windows Presentation Foundation (WPF) are not ported to. N ET 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.

    • . 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.

    • . NET Core

(1) Cross-platform. NET core is Microsoft's newest cross-platform framework that can be created with applications that can run on mac,linux. NET core supports UWP and ASP. CORE,UWP-Universal W in Windows 10 indows platform abbreviation. 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)

Iv.. 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

For example, the 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 set of base libraries for various touchscreen devices and ASP. NET programs that develop Windows systems.

v.. 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 the cross-platform open source compiler Ryujit, and Corert is the runtime using the advance compiler (Ahead of Time Compiler,aot), which 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 mainly used to compile Il machine code, and Roslyn is to compile C # or vb.net code 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 program 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 optimization compiled into machine code.

Compiling machine code using RyuJIT

dotnet Restore

dotnet Build--native--ilcpath <repo_root>\bin

\product\windows_nt.x64.debug\packaging\publish1

Compile to generate C + + code

dotnet Restore

dotnet build--native--cpp--ilcpath <repo_root>\bin\product\windows_nt.x64.debug\packaging\

Publish1--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:

vi.. 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 is equal, and the reflection is used to find filedinfo to determine whether the type is equal, The value is then compared 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.

Seven, 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.

New knowledge of. NET Core (reprint)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.