Interpretation of ASP.net 5 & MVC6 Series (4): Core Technology and Environment configuration _ self-study Process

Source: Internet
Author: User
Tags versions hosting

ASP.net 5 is the next generation of ASP.net, which is all rewritten to apply across platforms, and in the new version, Microsoft introduces the following tools and commands: DNVM, DNX, Dnu.

DNVM(. NET Version Manager): Microsoft offers DNVM capabilities to implement Cross-platform catalogs, DNVM is the ASP.net, a set of PowerShell scripts that launch the specified version of the ASP.net runtime, and can manage various versions of the NuGet operating environment (asp.net) at the same point in the same machine, and perform the appropriate upgrade operations at the same time by using the DNX tool.

DNX(. NET Execution Environment): DNX is the operating environment of the ASP.net program, which is used to start and run the ASP.net program. The running environment includes the compilation system, the SDK toolset, and the Native CLR hosting environment. You can use DNVM to manage various versions of DNX, such as a dnvm list command that lists all available DNX environments, and you can dnvm install 0.1-alpha-build-0446 install the specified version of Dnx to the. Dnx folder, where you can %USERPROFILE%\.dnx\runtimes find all versions of DNX that have been installed. Different operating systems have different versions of DNX.

Dnx.exe:d Nx.exe is a command-line tool for starting a hosted environment (self-hosting), and DNX is responsible for locating and invoking the CLR Native host when you start a program from a hosting environment using command-line code. The DNX command is the entry point for the entire running environment, which you can use dnx run to start the program.

dnu(DNX Utility): is a command-line package manager, contained within DNX, so as long as DNX is installed, you can use the DNU command, which can be used to recover packages, install packages, deploy packages, and so on. For example, the custom assembly in the Project.json is automatically downloaded and used.

DNX Architecture and Operation principle

DNX is the core of the ASP.net program, followed by the following two guidelines:

DNX should be self-contained, DNX cannot know which core CLR package to use after parsing the application dependency tree, so dnx cannot load any CLR until the parse tree is available, except for Roslyn compilers. Dependency Injection (Dependency injection, referred to as DI) runs through the entire system stack, and Di is a core part of DNX, and all class libraries on DNX are built on di.

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

Layer 0:native Process

The function of this layer is very simple, mainly is used to find and call Layer 1 CLR Native Host , and the system-related parameters passed to for native host subsequent use. Currently used under Windows DNX.exe to handle this, and IIS also provides a mediation (one provided under the Web site Bin directory AspNet.Loader.dll ) that can send requests, Native Host while Linux and Macs support this feature through their corresponding version of DNX.

DNX Usage:

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

--lib {paths}: The save address of an assembly DLL (typically a referenced third-party assembly and Project precompiled Assembly), which is where the managed code entry point of the Layer 2 layer can load assemblies.

--appbase {path}: The directory Saved by the program, the default is%cd%.

[ProgramName]: The name of the program in which the assembly (or DLL) it resides is Programe::Main saved --lib under the path, and the default value is appbase\project.json the name in. In most cases, the name is the program host () that contains the load chain Microsoft.Net.ApplicationHost . However, if your program contains an entry point (Main method) and is compiled into a --lib directory, you can use the name of the assembly as a [ProgramName] way to completely ignore the load chain and start your program directly.

Layer 1:clr Native Host

The content of this layer depends on the version of the CLR you have chosen, which has the following two responsibilities:

Start the CLR and which CLR to start depends on the version of the CLR you selected. If so Core CLR , the layer loads coreclr.dll , configures and starts the running environment, and then creates an application domain ( AppDomain ) to run all managed code. Calls the entry point () of managed code Layer 2 , and once Native Host the entry point returns the thread, the CLR's threads are cleaned up and shut down, such as uninstalling the application domain ( AppDomain ) and stopping the running environment.

Layer 2:managed Entry Point

The Layer Layer 2 (Managed code entry) is the first layer of writing managed code, with the following responsibilities:

Create LoaderContainer , which contains the required ILoaders , to ILoader load an assembly based on the name of the assembly. If the CLR needs an assembly, it LoaderContainer will use it ILoader to resolve the required assemblies. From --lib the path directory, load the assembly with the root ILoader and resolve its dependencies. The main entry point of the calling program.

Layer 3:application host/application

If the developer compiles the entire program into an assembly in the libpath directory, that layer is your application. When used, the assembly name that contains the entry point of the program is [ProgramName] passed in, and the Layer 2 layer calls the assembly directly.

In other cases, however, an application host () is used Application host to resolve the dependencies of the program and start running the program. Microsoft.Net.ApplicationHostis the application host provided by the operating environment and has the following responsibilities:

Resolves project.json the various dependent assemblies defined in. Add one ILoader to to LoaderContainer load the appropriate assembly from a variety of places, such as source code, NuGet, Roslyn, and so on. The entry point of the calling assembly is passed to the DNX.exe as the next argument.

Layer 4:application

This layer is a developer-developed program that runs on top of the application host.

Environment configuration:

To configure the operating environment of the ASP.net 5 program, you first need to install and configure the DNVM, different operating systems installed DNVM time is not the same, we will explain here about.

Windows installation Command :

Need to install PowerShell 3.0
@powershell-noprofile-executionpolicy unrestricted-command "IEX (New-object net.webclient ). Downloadstring (' Https://raw.githubusercontent.com/aspnet/Home/master/dnvminstall.ps1 ')) "

Linux:

Curl-ssl https://raw.githubusercontent.com/aspnet/Home/master/dnvminstall.sh | SH && Source ~/.dnx/dnvm/dnvm.sh

Mac OS X:
On the Mac, you first install the MAC system's own Package Manager homebrew ( http://brew.sh ) and use the brew tap aspnet/k command to assign the ASP.NET5-related git repository, such as the following command:

Brew Install DNVM

This command will be automatically ttps://www.nuget.org/api/v2 downloaded from the latest dnx, after downloading, if your system does not recognize DNVM, you will need to execute the following statement:

SOURCE dnvm.sh

After the above DNVM installation, the system will copy the DNVM file to the C:\Program Files\Microsoft DNX\Dnvm directory and C:\Program Files\Microsoft DNX\Dnvm add the directory to the environment variable so that it can be used globally. Note: There is only DNVM installed and no version of DNX is installed, and to install DNX, you can run DNVM or DNVM help to find the relevant commands, as follows:

DNVM upgrade [-x86][-x64] [-SVR50][-SVRC50] [-g|-global] [-proxy <address>]

1. Install the latest version of the DNX from the feed source
2. Set a default alias for the installed DNX
3. The user Path environment variable added to the Dnx bin
4.-g|-global installed in the global (other users can also use)
5.-f|-force Mandatory update to the latest version (even if the latest version has been installed)
6.-proxy access to a remote server using a specific address as a proxy

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 version of the DNX from the feed source
4. Add Dnx bin to the PATH environment variable of the current command line
5.-p|-persistent Add Dnx bin to the system PATH environment variable
6.-a|-alias sets the alias for the DNX of the specified installation
7.-g|-global is installed in the global context
8.-f|-force to force the installation of the specified DNX (even if the version is already 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 Remove Dnx bin from the PATH environment variable of the current command line
3.-p|-persistent Add Dnx bin to the system PATH environment variable
4.-g|-global combination uses-p to modify user path to system path

DNVM list//list all installed DNX versions
DNVM alias//List all DNX versions that have an alias defined DNVM alias
<alias>//display DNX alias name DNVM alias
<alias> <semver> [-x86][-x64] [-SVR50][-SVRC50]//Set alias to the specified DNX version

Managing DNU commands and feed source configurations for assemblies

When package management is done through the DNU command, the following commands are usually used:

dnu restore: Query all of the program's dependencies and download them all to the packages directory, which downloads the entire dependency package and other dependent packages on which these dependencies depend.
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/packages
outpot/appname
output/commandname.cmd

1. packages The directory contains the packages that are required by all applications.
2. The appName directory contains the code for all applications, and if other items are referenced, other projects that are referenced also create siblings of their respective projects, that is, the generated directories and appname siblings.
3. publish command, will be project.json in the commands node in the various commands, generate a response to the command line file, such as commands in the Web command, we can through dnx web (format: dnx <command> ) run it.

Because dnu in the internal use of the NuGet command, the management of the package, so use the time to properly configure the NuGet feed source, the current ASP.net 5 related packets are on the Myget feed, so we need to add this feed to normal operation. These configuration information is managed in a %AppData%\NuGet\NuGet.config file under Windows (or *nix under Mono ~/.config/NuGet/NuGet.config ). Examples are as follows:

<?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>

Under VS2015, you can set the tools--> options--> Nuget Package manager--> Package, as shown in the following illustration:

Also note that the address of the feed above is the daily build version of Asp.net5, and if you want to use a stable milestone (such as 1.0.0_ALPHA4), you need to use the following addresshttps://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)

The server is used to load the ASP.NET5 program on IIS to integrate with the IIS process, bypassing the System.Web performance enhancements and supporting Windows authentication, static file access, and so on. The rationale is to make a bridge between IIS and NDX.

Microsoft.AspNet.Server.WebListener (Weblistener)

This server, by Microsoft.AspNet.Hosting loading programs, services, work role outside of IIS, runs directly above the HTTP.sys core drive, consumes a little performance, and can benefit from port sharing, Windows authentication, and so on.

Microsoft.AspNet.Server.Kestrel (Kestrel)

The server Microsoft.AspNet.Server.Kestrel is designed to be used for cross-platform Web services (Windows, Macs, Linux, and so on) by loading it outside of IIS.

Reference content

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.