Interpretation of ASP. NET 5 & MVC6 series (4): Core Technology and Environment configuration, interpretation of ASP. NET

Source: Internet
Author: User

Interpretation of ASP. NET 5 & MVC6 series (4): Core Technology and Environment configuration, interpretation of ASP. NET

Asp.net 5 is the next generation of asp.net. This version is completely rewritten for cross-platform use. In the new version, Microsoft introduces the following tools and commands: DNVM, DNX, and DNU.

DNVM(. NET Version Manager): To implement cross-platform directories, Microsoft provides the DNVM function, which is ASP. NET, which is a group of Powershell scripts used to start a specified version of ASP.. NET runtime environment, and you can use the Nuget tool to manage various versions of ASP.. NET Runtime Environment (DNX), and upgrade accordingly.

DNX(. NET Execution Environment): DNX is the runtime Environment of ASP. NET programs. It is used to start and run ASP. NET programs. The running environment includes the compiling system, SDK tool set, and Native CLR host environment. You can use DNVM to manage various versions of DNX, suchdnvm listThe command can list all available DNX environments, whilednvm install 0.1-alpha-build-0446You can install the specified version of dnx to the. dnx folder.%USERPROFILE%\.dnx\runtimesFind all installed versions of DNX in the directory. Different operating systems have different DNX versions.

Dnx.exe: Dnx.exe is a command line tool used to start the Self-Host environment (Self-Hosting). When using the command line code to start the program in the Self-Host environment, dnx is responsible for searching and calling the CLR Native Host, the dnx command is the entry point of the entire running environment. You can usednx runTo start the program.

Dnu(DNX Utility): It is a command line Package Manager, which is included in DNX. Therefore, if DNX is installed, you can use the dnu command, it can be used to restore the program package, install the program package, and deploy the program package. the custom assembly in json is automatically downloaded for use.

DNX architecture and operating principle

DNX is the core of ASP. NET program running. It follows the following two principles:

DNX should be self-contained. DNX can only know which Core CLR package to use after resolving the application dependency tree. Therefore, DNX cannot load any CLR before obtaining the resolution tree, except for the Roslyn compiler. Dependency Injection (DI) runs through the entire system stack. DI is a core part of DNX, and all the class libraries on DNX are built on DI.

The hierarchical architecture of the DNX execution environment is as follows:

Layer 0: Native Process

The features of this layer are very simple, mainly used for searching and callingLayer 1InCLR Native HostAnd pass system-related parametersnative hostFor later use. Currently Used in WindowsDNX.exeIIS also provides an intermediary (AspNet.Loader.dll) Can forward requestsNative HostLinux and Mac support this function through the corresponding version of dnx.

DNX usage:

dnx.exe --lib {paths} --appbase {path} [ProgramName]

-- Lib {paths}: The save address of the Assembly dll (usually the referenced third-party assembly and project precompiled assembly). This address is the place where the hosted code entry point at Layer 2 can load the assembly.

-- Appbase {path}: Directory saved by the program. The default value is % CD %.

[ProgramName]: Program name, the Assembly where the program is located (or containsPrograme::Main.--libPath. The default value isappbase\project.json. In most cases, this name is a program host that contains the chain (Microsoft.Net.ApplicationHost). However, if your program contains the entry point (Main method) and is compiled--libDirectory, you can use the Assembly name[ProgramName], This method will completely ignore the chain loading and start your program directly.

Layer 1: CLR Native Host

The content of this layer depends on the CLR version you selected. This layer has the following responsibilities:

To start CLR, which CLR to start depends on the CLR version you select. If yesCore CLR, This layer will loadcoreclr.dll, Configure and start the running environment, and then create the application domain (AppDomain) To run all the managed code. The entry point for calling managed code (Layer 2), OnceNative HostWhen this thread is returned at the entry point, the CLR thread will be cleaned up and closed, for example, uninstalling the application domain (AppDomain) And stop the running environment.

Layer 2: Managed Entry Point

Layer 2 (managed code entry) is the first Layer for writing managed code. Its responsibilities are as follows:

CreateLoaderContainer(Including the requiredILoaders),ILoaderLoad the Assembly according to the Assembly name. If CLR needs an assembly,LoaderContainerTheILoaderTo parse the required assembly. Slave--libDirectory, use the rootILoaderTo load the Assembly and parse its dependencies. The main entry point of the calling program.

Layer 3: Application host/Application

If developers compile the entire program into an assemblylibpathDirectory, then this layer is your application. Use the Assembly name containing the program entry point[ProgramName]You can pass in the parameters,Layer 2The layer calls the Assembly directly.

However, an application host (Application host) To parse the program's dependent content and start the running program.Microsoft.Net.ApplicationHostIt is the application host provided by the running environment and has the following responsibilities:

Analysisproject.jsonDependencies defined in. SetILoaderAddLoaderContainerTo load the corresponding assembly from various places (such as source code, NuGet, And Roslyn. The Access Point of the call set, which is passed to dnx.exe as the next upload.

Layer 4: Application

This layer is the program developed by developers and runs on the application host.

Environment Configuration:

To configure the running environment DNX of ASP. NET 5, first install and configure DNVM. different operating systems do not have the same DNVM installation. Here we will give a rough explanation.

Windows Installation command:

// Install powershell 3.0 @ powershell-NoProfile-ExecutionPolicy unrestricted-Command "iex (new-object net. webclient). DownloadString ('https: // listener '))"

Linux:

curl -sSL https://raw.githubusercontent.com/aspnet/Home/master/dnvminstall.sh | sh && source ~/.dnx/dnvm/dnvm.sh

Mac OS X:
On Mac, install the Package Manager Homebrew (http://brew.sh), And usebrew tap aspnet/kThe command will be specified to the git repository related to ASP. NET5. For example, execute the following command:

brew install dnvm

This command will automaticallyttps://www.nuget.org/api/v2Download the latest DNX. After the download, if your system does not recognize dnvm, You need to execute the following statement:

source dnvm.sh

After the above DNVM is installed, the system will copy the dnvm fileC:\Program Files\Microsoft DNX\DnvmDirectory, andC:\Program Files\Microsoft DNX\DnvmDirectory is added to the environment variable for global use. Note: Only DNVM is installed and no version of DNX is installed. To install DNX, run dnvm or dnvm help to find related commands. The specific commands are as follows:

dnvm upgrade [-x86][-x64] [-svr50][-svrc50] [-g|-global] [-proxy <ADDRESS>]

1. Install the latest DNX from the feed source
2. Set a default alias for the installed DNX
3. Add the DNX bin to the user PATH Environment Variable
4.-G |-globalGlobal installation (available for other users)
5.-F |-forceForce Update to the latest version (even if the latest version has been installed)
6.-ProxyUse a specific address as the proxy when accessing the remote server

dnvm install <semver>|<alias>|<nupkg>|latest [-x86][-x64] [-svr50][-svrc50] [-a|-alias <alias>] [-g|-global] [-f|-force]

1. | install the specified DNX from the feed source
2. Install the specified DNX from the local file system
3. latest install the latest DNX from the feed source
4. Add DNX bin to the path environment variable of the current command line.
5.-p |-persistent Add the DNX bin to the system PATH environment variable.
6.-a |-alias sets an alias for the specified installed DNX
7.-g |-global installation
8.-f |-force forces the installation of the specified DNX (even if this version has been installed)

dnvm use <semver>|<alias>|none [-x86][-x64] [-svr50][-svrc50] [-p|-persistent] [-g|-global]

1. | add DNX bin to the path environment variable of the current command line
2. none: Delete the DNX bin from the path environment variable of the current command line.
3.-p |-persistent: add the DNX bin to the system PATH environment variable.
4.-g |-global combined use-p to change the user PATH to the System PATH

Dnvm list // list all installed DNX versions dnvm alias // list all DNX versions with alias defined dnvm alias <alias> // display the DNX name dnvm alias that defines the alias <alias> <semver> [-x86] [-x64] [-svr50] [-svrc50] // sets an alias for the specified DNX version

Manage the dnu command and feed source configuration of an assembly

When using the dnu command for package management, the following command is usually used:

dnu restore: Query all the dependent packages of the program and download them to the packages directory. This command downloads the entire dependent package and other dependent packages that these dependent packages depend on.
dun install <package id>: The install command is used to download the specified package and add it to the program.
dun publish: This command will package your program into a self-contained directory that can be run. It creates the following directory structure:

output/output/packagesoutpot/appNameoutput/commandName.cmd

1.packagesThe directory contains the packages required by all applications.
2.appNameThe directory contains the code of all applications. If other projects are referenced, the Directory of the same level of the project will be created in the referenced projects, that is, the generated directory will be the same level as the AppName.
3.publishCommands in the commands node in project. json are used to generate the command line files for the response, such as the web commands in commands.dnx web(Format:dnx <command>.

Because dnu uses the Nuget command internally to manage packages, you must correctly configure the Nuget feed source when using it. Currently, ASP. NET 5 related packages are all on myget feed, so we need to add this feed to run normally. These configurations are stored in Windows%AppData%\NuGet\NuGet.config(Or * Mono under nix~/.config/NuGet/NuGet.configFile. Example:

<?xml version="1.0" encoding="utf-8"?><configuration> <packageSources> <add key="AspNetVNext" value="https://www.myget.org/F/aspnetvnext/api/v2/" /> <add key="nuget.org" value="https://www.nuget.org/api/v2/" /> </packageSources> <disabledPackageSources /> <activePackageSource> <add key="nuget.org" value="https://www.nuget.org/api/v2/" /> </activePackageSource></configuration>

In VS2015, you can directly set it through Tools> Options> Nuget Package Manager> Package Sources, for example:

Note that the preceding feed address is the daily build version of asp. net5. If you want to use a stable milestone version (such as 1.0.0 _ alpha4), use the following address:https://www.myget.org/F/aspnetmaster/api/v2/

Web Server support

Microsoft provides several Web server support when implementing DNX, specifically as follows:

Microsoft. AspNet. Loader. IIS (Helios)

This server is used to load ASP. NET5 programs on IIS to integrate with the IIS process and BypassSystem.WebThis improves the performance and supports functions such as Windows Authentication and static file access. The principle is to bridge between IIS and NDX.

Microsoft. AspNet. Server. WebListener (WebListener)

This server passesMicrosoft.AspNet.HostingLoad programs, services, and work role outside of IIS. It runs directly on the Http. Sys core driver and consumes only a little performance, benefiting from Port Sharing and Windows authentication.

Microsoft. AspNet. Server. Kestrel (Kestrel)

This server passesMicrosoft.AspNet.Server.KestrelIt is designed for cross-platform Web Services (Windows, Mac, Linux, and so on ).

References

Https://github.com/aspnet/Home/wiki/DNX-structure
Https://github.com/aspnet/Home/wiki/Command-Line
Https://github.com/aspnet/Home/wiki/Version-Manager
Https://github.com/aspnet/Home/wiki/Package-Manager

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.