Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the latest development of .NET 2016?

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail about the latest development of .NET 2016, the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

New acquaintance with .NET 2016

.net 2016 Overview

As the latest development of .NET technology, .NET 2016 consists of three main blocks, as shown in the following figure:

On the far left is the .NET Framework 4.6. WPF, ASP.NET 4.x, and ASP.NET Core 1.0 can run on it. The middle part represents the .NET Core technology on which ASP.NET Core 1.0 and Universal Windows Platform (UWP) can run. Of course, you can also create console applications to run on the .NET Core. On the far right is Xamarin, a cross-platform mobile development framework based on Mono.

In .NET 2015, Microsoft brought us a brand new .NET, which is the .NET Core. An important part of the .NET Core is the new 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 Windows Store, resulting in optimized code that speeds up APP startup time and reduces memory consumption. Of course, you can also compile other .NET Core applications into Native Code and run them on Linux.

At the bottom of the image above, you can see that there is something shared between .NET Framework 4.6, .NET Core, and Xamarin. For example, some shared Libraries aggregates these Libraries into Package through the concept of Nuget packages for use by all the. NET platforms. Other runtime components (Runtime Components) are shared, such as GC and RyuJIT, a new JIT compiler that is not only faster than before, but also has better editing and continuation support when debugging. This feature allows you to edit the code while debugging and continue debugging without having to stop and restart the process. CLR, CoreCLR, and .NET Native use GC for instance destruction and memory recycling, and CLR and CoreCLR use RyuJIT compilers 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, as the latest version of the .NET Framework, has been continuously enhanced over the past decade. We use this Framework to build Windows Form, WPF, ASP.NET 4, and other applications. Although the ASP.NET Core application runs on the .NET Core, it can also run on the .NET Framework 4.6.

If you want to continue to develop applications using ASP.NET Web Form,. Then ASP.NET 4.6in NET Framework 4.6is your best choice. It is worth noting that you cannot run ASP.NET Web Form applications 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, that is, it is split into a large number of Nuget Package. In the application, you decide which Package is needed and keep it updated and uninstalled at all times. While the .NET Framework, which is part of the operating system, is not destined to be updated in real time, at the same time, over the past decade or so,. NET Framework has added a lot of new features, it has become bigger and bigger, and to make matters worse, it is impossible to remove old features that are no longer needed. For example, old collection classes are no longer used because generic collection classes are added, .NET Remoting is replaced by new communication technologies WCF and ASP.NET Web API, and LINQ to Sql is replaced by EntityFramework. And these old technologies exist all the time in the .NET Framework, and you have to accept them all.

Xamarin

Mono is a cross-platform .NET Framework developed by the open source community, while Xamarin is a cross-platform mobile application development framework built on Mono. It is believed that after Microsoft acquired Xamarin, Mono will receive strong support. NET Core's performance on the mobile side remains to be seen.

Compile the application using .NET Framework 4.6

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

Developer Command Prompt compiled code

When Visual Studio is installed, we can use the C # compiler to compile the code through the companion tool Developer Command Prompt.

1. Open notepad, write the following code in C #, name it HelloWorldApp.cs, and save it to the C:\ Code folder

The copy code is as follows:

Class Program {static void Main () {System.Console.WriteLine ("Hello World");}}

two。 Start Developer Command Prompt for VS2015 and type the following command:

Enter the C:\ Code folder cd C:\ Code use the C # compiler to compile the source code csc HelloWorldApp.cs view the file directory structure dir enter the EXE name to run the application HelloWorldApp

The running result is as follows:

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

Decompile assemblies using ILDASM

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

2.IL code statements are like assembly language instructions, and they are executed by .NET 's virtual machine, CLR. At run time, CLR loads IL code from the assembly, and the JIT compiler compiles it to Native Code, which is finally executed by CPU.

Type ildasm HelloWorldApp.exe in Developer Command Prompt and you will see that the ILDASM tool loads the compiled assembly:

Double-click the MANIFEST node to view the metadata:

You can see that the version of the .NET Metadata is 4.0.30319 and relies on the external assembly mscorlib, which is version 4.0.0.0. The screenshot above tells us that you need to install .NET Framework 4.0 or above to run this application.

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

Note the IL directive: ldstr (load string), nop (no operation), call,ret (return). Remember that IL is finally executed by CLR.

Compiling applications using .NET Core CLI

To use the latest .NET Core Command Line (CLI), make sure the. NET Core and CLI Tools are installed. You can visit 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 see the specific usage:

Create A. NET Core application using CLI

You need to use the following command through Developer Command Prompt:

1. Enter the C:\ Code folder cd c:\ code again

two。 Create a new folder mkdir SecondApp

3. Enter the new folder cd SecondApp

4. Use CLI to create the. NET Core application dotnet new

5. View directory structure dir

The dotnet new command creates a new .NET Core application with two files, Program.cs and project.json.

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 the project configuration file, and defines the basic information of the application in JSON format, such as version, buildOptions, authors, dependencies, frameworks, and so on.

{"version": "1.0.0 true *", "buildOptions": {"emitEntryPoint": true}, "dependencies": {"Microsoft.NETCore.App": {"type": "platform", "version": "1.0.0-rc2-3002702"}}, "frameworks": {"netcoreapp1.0": {"imports": "dnxcore50"}

In the above JSON format, because the Main method serves as the EntryPoint of the application, you need to set the emitEntryPoint property under the buildOptions node to true.

The dependencies node represents the packages that the application depends on, and only Microsoft.NETCore.App dependencies are added by default. It is worth noting that Microsoft.NETCore.App is a Nuget Package of reference type, which in turn 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, applications only support .NET Core 1.0, denoted by the alias netcoreapp1.0. The imports node under netcoreapp1.0 refers to the old name dnxcore50. This allows us to still use the package with the old name.

Next, download the required dependencies through dotnet restore

Use project.lock.json to view the downloaded package version.

To compile the application, use the command dotnet build.

Finally, run the application using dotnet run.

It is worth noting that in framework, you can also add application support for other frameworks, adding the string net46, indicating that the current console application is built on top of the .NET Framework 4.6:

"frameworks": {"netcoreapp1.0": {"imports": "dnxcore50"}, "net46": {}}

Unfortunately, an exception occurred after dotnet build. As follows (Note: the current version is .NET Core RC 2)

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

{"version": "1.0.0 true *", "buildOptions": {"emitEntryPoint": true}, "frameworks": {"netcoreapp1.0": {"imports": "dnxcore50", "dependencies": {"Microsoft.NETCore.App": {"type": "platform", "version": "1.0.0-rc2-3002702"}, "net46": {}}

After dotnet build, you generate two folders, net46 and netcoreapp1.0, respectively. Using the ILDasm (see previous section) tool, you can see a very important difference between them by opening the folder. Applications that use .NET Framework are compiled to generate EXE applications that contain IL and rely on mscorlib assemblies, while applications that use .NET Core compile to generate DLL that contains IL, depending on System.Console and System.Runtime assemblies.

Finally, use dotnet run-- framework net46 to specify the version of famework as .NET Framework 4.6 to view the running results.

In addition to dotnet build and dotnet run, you can also package (dotnet pack) and dotnet publish applications through CLI.

Dotnet pack creates a NuGet Package:

It is a Nuget Package with the suffix nupkg. You can change it to .zip to unzip and view the contents.

Dotnet publish has released a project that can be used to deploy .NET, and you can add runtime to 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 publishing across platforms, specify the runtime with the parameter-r, such as dotnet publish-r ubuntu.14.04-x64, and finally copy the published folder (ubuntu.14.04-x64/publish) to the specified OS to be executed. You do not need to install the .NET Core and .NET Core SDK, just install the Libraries that the .NET Core depends on.

So much for sharing the latest development of .NET 2016. I hope the above content can be of some help to you and learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report