Thick and thin hair, embracing. NET 2016_ Practical Tips

Source: Internet
Author: User
Tags dotnet mscorlib pack

First knowledge of. NET 2016

. NET 2016 Overview

. NET 2016 is the latest development of. NET technology, as shown in the following illustration, which consists of three main blocks :

The left side represents the. NET Framework 4.6,wpf, asp.net 4.x, and ASP.net Core 1.0 that can be run on it. The middle part represents. NET core technology, which ASP.net core 1.0 and Universal Windows Platform (UWP) can run on top of it. Of course, you can also create a console application to run on. NET Core. At the far right is Xamarin, a Cross-platform mobile development framework based on Mono.

At. NET 2015, Microsoft brought us a new. NET, one of the key components of. NET Core. NET core is the new runtime (Runtime): CoreCLR. In addition to using the CORECLR runtime,. NET can also be compiled into Native Code. UWP automatically uses this feature, and the application is compiled into Native code after it is submitted to the Windows Store, which eventually generates optimized coding that allows APP startup time to accelerate and reduce memory consumption. You can of course compile other. NET Core applications into Native Code and run on Linux.

At the bottom of the image above, you can see that there are some things that are shared between the. NET Framework 4.6,. NET Core, and Xamarin. For example, some shared libraries, through the concept of Nuget package, these libraries pooled in Package for all the. NET platform. There are also runtime components (Runtime components) that are shared, such as GC and Ryujit, a new JIT compiler that is not only faster than before, but also has better support for editing and continuing when debugging. This feature allows you to edit the code while debugging and continue debugging without having to stop and restart the process. The CLR, coreclr,. NET Native use GC for instance destruction and memory recycling, and the CLR and coreclr use the Ryujit compiler to compile IL code into Native code. Of course, the new compiler Roslyn is also shared.

. NET Framework 4.6

The. NET Framework 4.6, the latest version of the. NET Framework, has been continuously enhanced over the past more than 10 years. We use this Framework to build applications such as Windows Form, WPF, asp.net 4, and so on. Although the ASP.net core application runs on. NET core, it can also run on the. NET Framework 4.6.

If you want to continue using the ASP.net Web Form to develop your application, the ASP.net 4.6 in NET Framework 4.6 is your best choice. It is important to note that you cannot run the ASP.net Web Form application on the. NET Core.

. NET Core 1.0

. NET Core 1.0 (currently RC2) is the new. NET, which is a truly cross-platform implementation compared to Mono. The. NET core is designed as a modular approach, which is split into a large number of Nuget Package. In your application, you decide what Package you need and keep it updated and uninstalled at any time. The. NET Framework, which is part of the operating system, is doomed to not be updated in real time, and over the past more than 10 years, the. NET Framework has added a lot of new features, and it's getting bigger and worse, it's not possible to remove old features that you no longer need. For example, the old collection class is no longer used because the generic collection class joins,. NET Remoting is replaced by the new communication technology WCF, ASP.net Web API, and LINQ to SQL is EntityFramework replaced. And these old technologies, which have always existed in the. NET Framework, you have to accept them completely.

Xamarin

Mono is a cross-platform. NET framework developed by the open source community, while Xamarin is a framework for the development of Cross-platform mobile applications built on Mono. It is believed that after Microsoft acquired Xamarin, Mono will be strongly supported, and the performance of. NET Core on the mobile side remains to be seen.

Compiling an application using the. NET Framework 4.6

Creating a "Hello World" application is the beginning of learning a new technology. Here, in order to better understand. NET Core, we are not going to use visual Studio 2015 for development.

Developer Command Prompt Compile code

When Visual Studio is installed, we can compile the code using the C # compiler via the kit Developer Command Prompt.

1. Open Notepad, use C # to write the following code, named HelloWorldApp.cs and save to the C:\Code folder

Copy Code code as follows:
class Program { static void Main() { System.Console.WriteLine("Hello World");}}

2. Start Developer command Prompt for VS2015, type the following:

Enter the C:\Code folder CD C:\Code use the C # compiler to compile source code csc HelloWorldApp.cs View File directory structure dir enter exe name to run application Helloworldapp

The results of the run are as follows:

Note that your source code file HelloWorldApp.cs has been compiled into the assembly HelloWorldApp.exe. When you enter the Helloworldapp name to run the application, it is eventually loaded and run by the. NET Framework 4.6 and its CLR.

To decompile an assembly using ILDASM

The 1.c# compiler converts the source code to IL code and stores it in an assembly (DLL or EXE).

2.IL code statements are like assembly-language directives that are executed by the. NET virtual machine, which is the CLR. At run time, the CLR loads the IL code from the assembly, and the JIT compiler compiles it into Native code, which is finally handed over to the CPU.

In the Developer Command Prompt enter ILDasm HelloWorldApp.exe, you will see the ILDASM tool loading the compiled assembly:

Double-click the MANIFEST node to view the meta data:

You can see that the. NET Metadata version is 4.0.30319 and relies on external assembly mscorlib, its version is 4.0.0.0, and the screenshot above tells us that to run this application requires more than 4.0 of the. NET Framework to be installed.

Close the MANIFEST window, expand the Program node, and double-click the Main method:

Note IL directives: ldstr (Load String), NOP (no operation), Call,ret (return). Remember that IL is eventually executed by the CLR.

Compiling an application with the. NET Core CLI

To use the latest. NET Core Command Line (CLI), make sure that the. NET core and CLI Tools are installed. You can access https://dotnet.github.io/ to install them for Windows, Linux, and OS X.

After successfully installing the. NET Core CLI Tools, you can type dotnet help in Developer Command Prompt to view specific uses:

Creating. NET Core applications using the CLI

You need to use the following command via Developer command Prompt:

1. Enter C:\Code folder CD again C:\Code
2. Create a new folder mkdir Secondapp
3. Enter new Folder CD Secondapp
4. Create. NET core applications using the CLI dotnet new
5. View directory Structure dir

The dotnet New command creates an additional. NET Core application that contains two files, Program.cs and Project.json respectively.

Program.cs is a simple console application that outputs "Hello world"

Using System;
Namespace Consoleapplication
{public
 class program
 {public
 static void Main (string[] args)
 {
  Console.WriteLine ("Hello world!");}}


Another file: Project.json, which is a project profile and defines the basic information for the application in JSON format, such as version, Buildoptions, authors, dependencies, frameworks, and so on.

{
 "version": "1.0.0-*",
 "Buildoptions": {
 "emitentrypoint": True
 },
 "dependencies": {
 ' Microsoft.NETCore.App ': {
 ' type ': ' Platform ',
 ' version ': ' 1.0.0-rc2-3002702 '
 }
 },
 ' Frameworks ': {' netcoreapp1.0 ':
 {
 ' imports ': ' Dnxcore50 '
 }
 }
}

In the JSON format above, because the Main method acts as the entry point for the application, you need to set the Emitentrypoint property under the Buildoptions node to True Entry.

The dependencies node represents the packages of the application dependencies, and only Microsoft.NETCore.App dependencies are added by default. It is noteworthy that Microsoft.NETCore.App is a reference type of NuGet Package, which references other NuGet Package. The advantage is to avoid adding a lot of other package.

The frameworks node lists the frameworks supported by the application. By default, the application supports only. NET Core 1.0, which is represented by alias Netcoreapp1.0. The Imports node under netcoreapp1.0 references the old name Dnxcore50. This allows us to still use the package of the old name.

Next, download the required dependencies via dotnet restore

Through Project.lock.json, view the package version of the specific download.

To compile the application, use the command dotnet build.

Finally, run the application using the dotnet run.

It is noteworthy that the application can also be added to support other frameworks in the framework, adding string net46 to indicate that the current console application is built on the. NET Framework 4.6:

"Frameworks": {"
 netcoreapp1.0": {
 "Imports": "Dnxcore50"
 },
 "Net46": {}
}

Unfortunately, an exception occurred after the dotnet build. As shown below (note: The current version is. NET Core RC 2),

You can see that the exception information is System.Runtime.Loader does not support the. NET Framework 4.6. Just a very general information, personal guess Runtime Loader only support coreclr loading, in Github (https://github.com/dotnet/corefx/issues/8453), also should testify my point of view. A temporary workaround is to move the dependencies node into the netcoreapp1.0 under frameworks:

{
 "version": "1.0.0-*",
 "Buildoptions": {
 "emitentrypoint": True
 },
 "Frameworks": {
 " netcoreapp1.0 ": {
 " Imports ":" Dnxcore50 ",
 " dependencies ": {
 " Microsoft.NETCore.App ": {"
  type ":" Platform ",
  " version ":" 1.0.0-rc2-3002702 "}}
 ,
 " Net46 ": {}
}}

After the dotnet build, generate two folders net46 and netcoreapp1.0 respectively, using the ILDasm(see the previous section) tool, open folder can see a very important difference between them, use. NET Framework is compiled to generate an EXE application containing IL and relies on the mscorlib assembly, and when the. NET Core application is compiled, a DLL containing IL is generated, dependent on System.Console and system.ru Ntime Assembly.

Finally, the dotnet run--framework net46 specifies that the version of Famework is the. NET Framework 4.6 View run results.

In addition to dotnet build and dotnet run, you can also package (dotnet Pack) and publish (Dotnet publish) applications via the CLI.

The dotnet pack creates a NuGet Package:

It is a suffix named nupkg Nuget Package, you can change it to. zip, unpack and view the contents.

Dotnet Publish publishes a can be used to deploy the. NET project, you can add runtime in Project.json:

' runtimes ': {
 ' ubuntu.14.04-x64 ': {},
 ' win7-x64 ': {},
 ' win10-x64 ': {},
 ' osx.10.10-x64 ': {},
 ' Osx.10.11-x64 ": {}
}"

Then use dotnet Restore to download the specified runtimes. When Cross-platform Publishing, specify runtime via parameter-R, such as Dotnet Publish-r ubuntu.14.04-x64, which can be executed by copying the folder (Ubuntu.14.04-x64/publish) after the release to the specified OS. You do not need to install the. NET core and. NET core SDK, just install the. NET core-dependent libraries.

Summary

Farewell to. NET development for more than a year, did not expect to happen so many incredible technology, seize the time to add. I have recruited people, also asked for the post, deeply appreciate the domestic. NET ecological environment, I hope. NET Core can lead us to a bright road, like a wisp of sunshine in the forest, to bring hope.

This paper is the main original wood Wancheng.
Original address: http://www.cnblogs.com/OceanEyes/p/dotnet_2016_overview.html

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.