Home > Backend Development > C#.Net Tutorial > Detailed explanation of Core's ASP method for implementing comprehensive literacy stickers

Detailed explanation of Core's ASP method for implementing comprehensive literacy stickers

Y2J
Release: 2017-05-04 10:55:19
Original
1731 people have browsed it

This article mainly introduces .NET Core. .NET Core is an open source and universal development framework that supports cross-platform, that is, it supports development and deployment on Windows, macOS, Linux and other systems. If you are interested, you can learn more.

1. Preface

It has been fourteen years since the release of .NET. With the continuous iteration of the version update, .NET's performance on the Windows platform is getting better and better. It can be said that .NET can complete almost all application types on the Windows platform.

It’s just that Windows succeeds and Windows fails. In the past fourteen years, except for some “private” versions, .NET has not been able to get rid of the limitations of the Windows platform with official support, “open source” and “cross-platform” These two words are also the pain in the hearts of all .NET developers. Finally, .NET Core emerged, which allowed developers to go beyond Windows with official and community support and write debug and deploy .NET programs on macOS and Linux mainstream distributions.

2. .NET Core Introduction

2.1 What is .NET Core

.NET Core is an open source general development framework that supports cross-platform, that is, it supports development and deployment on Windows, macOS, Linux and other systems, and can be used in hardware devices, cloud services, and embedded/IoT solutions. The source code of .NET Core is placed on GitHub and is jointly supported by Microsoft officials and the community.

It has a "subset-superset" relationship with the traditional .NET Framework, or you can simply think of it as a cross-platform version of the .NET Framework (based on the BCL level). This is because in the current version (1.0), most of the core code in .NET Core is inherited and rewritten from the .NET Framework, including Runtime and Libraries (such as GC, JIT, some types).

Tucao: I can only thank Microsoft for not having to read "CLR via C#" in vain. It took me half a year to finish it.

The current version of .NET Core 1.0 is a very small version. The core, APIs and tools are not complete, but as .Net Core continues to improve, supplementary Apis and innovations will be integrated into the .NET Framework. In other words, .NET Core Microsoft will update .NET Framework and .NET Core at the same time. They are like two brothers working together to get rich (to whom? Of course, the .NET developers), to achieve the so-called world harmony, and also It is .NET Standard 2.0

I have to mention a concept called .NET Standard Library. As the official support standard for .NET platform APIs development, it requires all .NET framework APIs to be backward compatible. For example, .NET Framwork 4.6 supports .NET Standard Library 1.3, .NET Framwork 4.6.2 framework supports .NET Standard Library 1.5, and .NET Core 1.0 framework supports 1.6 standard.

The final outlook is as follows:

##2.2 Composition of .NET Core

①.NET Runtime


That is CoreCLR. As mentioned before, there is no difference between CoreCLR and the .NET Framework's CLR. The process management, GC, and JIT (RyuJIT compiler) are also the same, but they are optimized for the server system. Now CLR and CoreCLR are also being updated simultaneously, but what is certain is that CoreCLR is the future of .NET, and 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 compiler)

That is, CLI tool and Roslyn compiler. It can be obtained through .NET Core SDK (.NET Core Development Kit).

④dotnet'app host


is used to select and execute the corresponding runtime, provide component loading principles and start .NET Core applications. The SDK is also launched through the same procedure.

Tips: Do you think of the MSCorEE.

dll shim, which also carries the work of selecting the CLR version for .NET applications on the Windows platform

2.3 Features of .NET Core

①Cross-platform


Can run on Windows, macOS, Linux

②Flexible deployment mechanism

1.Portable applications


This deployment mechanism is similar to the traditional .NET Framework, as long as .NET exists on the target platform Core Runtime is enough.

2.Self-contained application (self-hosted application)


As the name suggests, this deployment mechanism packages the application and runtime together, even if there is no

installation# on the target platform ##.NET Core Runtime can also be used normallyThe second method is also different from .NET Native. It still uses CoreCLR, while .NET Native uses CoreRT as the runtime. For details, please see dotnet/corert


③Command line tool

All running scripts of the .NET program can be executed using command line tools (cmd, bash). Here are several common donnet commands

Commands 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 Build the .NET project
dotnet publish Generate a distributable .NET project (including the associated Runtime)
dotnet run Compile and run .NET projects immediately (more suitable for exe-type projects)
dotnet repl Guide interactive dialogue
dotnet pack Encapsulate the project output into a NuGet package

④Compatibility

Passed .NET Standard Library is compatible with .NET Framework, Xamarin, and Mono

⑤Open source

.NET Core is affiliated with the .NET Foundation and is officially supported by Microsoft using MIT and Apache. 2 Open source agreement, the document agreement follows CC-BY

2.4 Development language

The programming language supported in .NET Core 1.0 version is only C# (F# and VB have not been implemented yet). An open source language compiler, Roslyn, is also mentioned here. It is responsible for compiling the code into the IL language we are familiar with, and then compiles it into the machine language familiar to the machine through the AOT or JIT compiler. .

3. Get Started

The following content demonstrates the command line generation and publishing demo under Windows 10 and CentOS 7.2

3.1 Win 10

3.1.1 Install .NET Core SDK and .NET Core Runtime

.NET Core SDK = Use .NET Core to develop applications. NET Core Runtime and SDK+CLI tools

3.1.2 Simple running results

Open cmd, enter mkdir .project (create directory), cd .\.project (enter directory), dotnet new ( Create a new initial project), dotnet restore (restore dependencies), dotnet run (run) to run the first Hello World program

3.2 CentOS 7.2 (local Hyper -V)

3.2.1 Installation and operation

For details, please see: www.microsoft.com/net/core#windowsvs2015. The approximate command is as follows

sudo yum install libunwind libicu #安装libunwind,libicu包
curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?LinkID=809131 #下载dotnet-dev-centos-x64.1.0.0-preview2-003121.tar文件,有时会因为网络问题下载较慢,耐心等待即可,当然也可以手动下载后放到目录下。
sudo mkdir -p /opt/dotnet && sudo tar zxf dotnet.tar.gz -C /opt/dotnet #创建目录并解压已下载文件
sudo ln -s /opt/dotnet/dotnet /usr/local/bin #将目录链接到$PATH下,否则dotnet命令无法识别
mkdir hwapp
cd hwapp
dotnet new #创建默认.NET Core应用
dotnet restore #还原依赖包
dotnet run #运行,结果将显示Hello World!
Copy after login

After the sixth line of command, you can use dotnet --info to check whether the link is successful, which is displayed as follows

.NET Command Line Tools (1.0.0-preview2-003121)
Product Information:
 Version:   1.0.0-preview2-003121
 Commit SHA-1 hash: 1e9d529bc5
Runtime Environment:
 OS Name:  centos
 OS Version: 7
 OS Platform: Linux
 RID:   centos.7-x64
Copy after login

The above steps can be found on the .NET Core official website. You can see that the application has been successfully connected after a simple dotnet new, dotnet restore , it starts running after the dotnet run command, but this is actually similar to debugging and running in the development environment, and the new application on win cannot be directly run across platforms on Linux at this time, so we have to mention the dotnet publish command again.

3.2.2 Release of Self-contained applications

(1) Modify the project.json file

We now follow the steps to create a new HW console application self under win10 , according to the official document requirements, we need to replace the original project.json file with the following content (Delete"type": "platform", and add the runtimes node)

{
 "version": "1.0.0-*",
 "buildOptions": {
 "debugType": "portable",
 "emitEntryPoint": true
 },
 "dependencies": {},
 "frameworks": {
 "netcoreapp1.0": {
  "dependencies": {
  "Microsoft.NETCore.App": {
   "version": "1.0.0"
  }
  },
  "imports": "dnxcore50"
 }
 },
 "runtimes":{
 "win10-x64":{}, #win10平台
 "centos.7-x64":{} #centos7.2平台
 }
}
Copy after login

(2) Execute restore Execute the dotnet restore command after the publish operation

to restore the platform. This step takes a long time. Although there are only two platforms, it took a long time the first time. Then proceed to dotnet publish -r centos.7-x64 -c release.

dotnet publish instructions see dotnet-publish - Packs the application and all of its dependencies into a folder getting it ready for publishing

(3) in After running the above operations on the Linux platform

, we only need to upload the published folder (bin/release/netcoreapp1.0/centos7-x64/publish, including self.exe) Go to the project (new) folder in the Linux root directory and enter the command

# in the Shell. After modifying the executable permissions, you can successfully run "Hello World". This is Our deployment method of "Self-contained applications"

4. Summary

4.1 Epilogue

At this point, .NET The study of Core has come to an end. The above content briefly introduces the composition and characteristics of .NET Core. It also successfully runs examples on Windows and Linux systems through two different deployment methods. Compared with the previous fool-proof deployment of .NET Framework, the novelty of .NET Core really makes my eyes shine. Next, I will also record the learning of .NET Core and ASP.NET Core. Corrections are welcome.

The above is the detailed content of Detailed explanation of Core's ASP method for implementing comprehensive literacy stickers. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template