This article focuses on the. NET core,.net Core is an open-source, common development framework that supports cross-platform, i.e. support for development and deployment on systems such as Window,macos,linux can be understood.
1. Preface
. NET has been in circulation for 14 years now. As the version continues to iterate over the update. NET on the Windows platform is also getting better, and it can be said that all the application types on the Windows platform. NET can be done almost.
Just become also windows, defeated also Windows, which for 14 of years, in addition to part of the "folk" version. NET has not been able to get rid of the limitations of the Windows platform with official support, "open source" and "cross-platform" are all the two words. NET Developer's pain. Finally,. NET core emerged, which allows developers to go out of windows with official and community support, writing debugging and deploying. NET programs on Macos,linux mainstream distributions.
2. Introduction to. NET Core
What is 2.1. NET Core
. 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 the. NET core is on GitHub , supported by Microsoft's official and community partners.
It is a "subset-superset" relationship with the traditional. NET Framework, or you can simply assume that it is a cross-platform version of the. NET Framework (as seen on the Bcl-based level). This is because in the current version (1.0), most of the core code in. NET core is inherited from the. NET Framework, including runtime and libraries (such as GC, JIT, partial types).
Spit Groove: Can only thank Microsoft "CLR via C #" Do not look white, I have seen a little half a year before reading
Now the. NET Core 1.0 release is a small core, and the APIs and tools are not complete, but as the. NET core continues to evolve, complementary APIs and innovations are integrated into the. NET Framework. That is,. NET core Microsoft updates the. NET Framework and. NET core at the same time, and they are like two brothers who work together to get rich. Of course it is. NET developers) to achieve the so-called World of Datong, which is. NET Standard 2.0
Here we have to mention a concept called. NET standard Library. As. NET Platform APIs development official support standard, it requires all the. NET Framework APIs follow backwards compatibility. For example,. NET Framwork 4.6 supports the. NET Standard library 1.3,.net framwork 4.6.2 Framework, which supports. NET Standards Library 1.5, while the. NET Core 1.0 Framework supports 1.6.
The final Outlook is as follows:
2.2. NET Core Composition
①.net Runtime
That is coreclr. As previously mentioned, CORECLR is no different from the CLR of the. NET framework, Process Management, Gc,jit (RyuJIT compiler) These parts are all the same, just for the server system to do the corresponding optimization. Now the CLR and CORECLR are also synchronizing updates, but to be sure, CORECLR is the future of. NET, and the CLR will exist as a means of compatibility.
②framework Libraries,
That is Corefx. Including collection classes, file system processing classes, XML processing classes, asynchronous task classes, etc.
③SDK Tools and Language Compilers (SDK tools and compilers)
That is, the CLI tool and the Roslyn compiler. Available through the. NET core SDK (. NET core Development Kit).
④dotnet ' app host
Used to select and execute the corresponding runtime, provide component onboarding principles, and start the. NET core application. The SDK is also started by the same program.
Tips: Do you think of MSCorEE.dll this gasket, which also carries the work of choosing a CLR version of a. NET application on the Windows platform
2.3. NET Core Features
① Cross-platform
Can be run on Windows,macos,linux
② Flexible deployment mechanism
1.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.
2.self-contained Application (self-hosted application)
As the name implies, this deployment mechanism packages the application and runtime together, even if no. NET Core Runtime is installed on the target platform
The second approach is not the same as. NET native, still using CORECLR, while. NET native uses Corert as the runtime, see Dotnet/corert for more information
③ command-line tools
. NET program all run scripts can be executed with command-line tools (Cmd,bash) Here are a few common donnet commands
| instruction |
Help |
| dotnet New |
Generate new basic. NET Project content (including Project.json, Program.cs, and Nuget.config |
| dotnet Restore |
Restore the referenced NuGet package |
| dotnet Build |
Building a. NET project |
| dotnet Publish |
Generate a redistributable. NET project (including the Runtime that belongs to) |
| Dotnet Run |
Compile and run. NET projects immediately (more suitable for EXE projects) |
| dotnet REPL |
Guide Interactive Conversations |
| Dotnet Pack |
Package the output of a project into a NuGet package |
④ compatibility
Compatible with. NET Framework,xamarin,mono through the. NET Standard library
⑤ 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
2.4 Development language
The programming languages supported in. NET Core 1.0 are in C # only (F # and VB are not implemented), and there is an open source language compiler, Roslyn, which compiles the code into our familiar Il language, which is then compiled by the AOT or JIT compiler into machine language that is familiar to machines.
3. Get Started
The following shows the command line build and release demo under WINDOWS10 and CentOS 7.2
3.1 Win 10
3.1.1 Installing the. NET Core SDK and. NET Core Runtime
. NET core SDK = using. NET core Development app. NET core Runtime and SDK+CLI tools
3.1.2 Simple Run Results
Open cmd, enter mkdir. Project (Create directory), CD. \.project (enter directory), dotnet new (new initial project), dotnet Restore (Restore dependent), dotnet Run runs a first Hello world program
3.2 CentOS 7.2 (local hyper-V)
3.2.1 Installation and operation
For details, see: www.microsoft.com/net/core#windowsvs2015, the General order is as follows
sudo yum install libunwind libicu #安装libunwind, libicu pack Curl-ssl-o dotnet.tar.gz https://go.microsoft.com/fwlink/? linkid=809131 #下载dotnet-dev-centos-x64.1.0.0-preview2-003121.tar files, sometimes because of network problems download slow, patient wait, of course, can also be manually downloaded and put into the directory. sudo mkdir-p/opt/dotnet && sudo tar zxf dotnet.tar.gz-c/opt/dotnet #创建目录并解压已下载文件sudo ln-s/opt/dotnet/dotnet /usr/local/bin #将目录链接到 $PATH, otherwise the dotnet command does not recognize mkdir hwappcd hwappdotnet new #创建默认. NET Core app dotnet restore #还原依赖包dotnet Run #运行, the result will show Hello world!
After the six-line command, you can use dotnet--info to see if the link is successful, as shown below
. NET Command Line Tools (1.0.0-preview2-003121) Product information:version: 1.0.0-preview2-003121 Commit SHA-1 Hash:1e9d529bc5runtime environment:os Name: centos os version:7 os platform:linux RID: centos.7-x64
The above steps can be found on the. NET Core Web site, and you can see that the app runs after the simple dotnet new, dotnet Restore, dotnet Run command, but this is actually similar to the debug run in the development environment, And win on the new application at this time can not directly run across the platform to Linux, so we have to mention the dotnet Publish command
3.2.2 Self-contained applications released
(1) Modify the Project.json file
We're win10 now. Follow step new A new HW console application self, as required by official documentation, we need to replace the original Project.json file with the following (delete "type": "Platform" and add runtimes node)
{"Version": "1.0.0-*", "buildoptions": {"Debugtype": "Portable", "Emitentrypoint": true}, "dependencies": {}, "Framewor KS ": {" netcoreapp1.0 ": {" dependencies ": {" Microsoft.NETCore.App ": { " version ":" 1.0.0 " } }, "Imports": "Dnxcore50"}, "Runtimes": {"win10-x64": {}, #win10平台 "centos.7-x64": {} #centos7.2 Platform}}
(2) Perform restore and publish operations
The dotnet Restore command is then executed for the platform restore operation. This step takes a long time, although it is only two platforms, and the first time it took longer. followed by the dotnet publish-r centos.7-x64-c release.
dotnet Publish instructions See Dotnet-publish-packs the application and all of their dependencies into a folder getting it ready for PU Blishing
(3) running on the Linux platform
After this, we only need to upload the Post folder (Bin/release/netcoreapp1.0/centos7-x64/publish, including Self.exe) to the Linux root directory in the project (new) folder, Entering directives in the shell
After modifying executable permissions, you can successfully run "Hello World", which is how we deploy "self-contained applications"
4. Summary
4.1 Epilogue
At this point, the. NET core learning is over, with a brief introduction to the composition and nature of. NET core, as well as the successful running of examples on Windows and Linux systems in two different deployment modes. Compared to the previous. NET Framework for a fool-only deployment, the novelty of. NET core really made my eyes shine. Next, I'll also record the learning of. NET core and ASP.