Interpreting ASP 5 & MVC6 Series (4): Core technology and environment configuration

Source: Internet
Author: User
Tags hosting

Original: Interpretation of ASP. 5 & MVC6 Series (4): Core technology and environment configuration

ASP. NET 5 is the next generation of ASP. This version is all rewritten for cross-platform, and in the new version, Microsoft introduces the following tools and commands: DNVM, DNX, DNU.

DNVM(. NET Version Manager): Microsoft provides DNVM functionality for cross-platform catalogs DNVM is the bottom-level content of ASP., a set of PowerShell scripts that launches the specified version of the ASP. NET runtime environment, and can manage various versions of the ASP. NET runtime Environment (DNX) at the same point on the same machine, and perform appropriate upgrade operations.

DNX(. NET execution Environment): DNX is the operating environment of the ASP, which is used to start and run the ASP. The runtime 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 dnvm list commands to list all available DNX environments, and you dnvm install 0.1-alpha-build-0446 can install the specified version of DNX into the. Dnx folder, where you can %USERPROFILE%\.dnx\runtimes find all the installed versions of DNX in the directory. Different operating systems have different versions of DNX.

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

dnu(DNX Utility): is a command-line package Manager that is included in the 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 assemblies in Project.json are downloaded automatically for use.

DNX Architecture and operating principle

DNX is the core of the ASP, which follows two guidelines:

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

The hierarchical 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 inside CLR Native Host , and the system-related parameters passed to native host , for subsequent use. Currently used under Windows DNX.exe to handle this, IIS also provides a mediation (provided in the site Bin directory AspNet.Loader.dll ) to forward requests Native Host , while Linux and Mac support this feature through their corresponding version of DNX.

DNX Usage:

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

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

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

[ProgramName]: Program name, the program is located in the assembly (or the containing Programe::Main DLL) is saved --lib under the path, the default is appbase\project.json the name. 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 (the Main method) and is compiled into a --lib directory, you can use the name of the assembly as a way to [ProgramName] completely ignore the load chain and start your program directly.

Layer 1:clr Native Host

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

    1. Starting the CLR, which CLR to start depends on the CLR version you choose. If it is Core CLR , the layer loads coreclr.dll , configures, and starts the running environment, and then creates the application domain ( AppDomain ) to run all managed code.
    2. Call the entry point () of managed code, and Layer 2 once Native Host the entry point returns to that thread, it cleans up and shuts down the CLR's thread, for example, unloads the application domain ( AppDomain ) and stops the running environment.
Layer 2:managed Entry Point

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

    1. Create LoaderContainer (which contains the required ILoaders ), which ILoader is responsible for loading the assembly based on the name of the assembly. If the CLR needs an assembly, it LoaderContainer will use it ILoader to parse the required assembly.
    2. From --lib the path directory, load the assembly with the root ILoader and resolve its dependencies.
    3. The main entry point of the calling program.
Layer 3:application host/application

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

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

    1. project.jsonthe various dependent assemblies defined in the parse.
    2. Add one ILoader to to LoaderContainer load the corresponding assembly from various places, such as source code, NuGet, Roslyn, and so on.
    3. Invokes the entry point of the Assembly, passing it as the next argument to DNX.exe.
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. DNX, you first need to install and configure the DNVM, different operating systems install DNVM is not the same time, we are here to explain about.

Windows installation Commands :

//需要安装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 a Mac, you first install the Package Manager homebrew () of the Mac system itself, http://brew.sh and use the brew tap aspnet/k command to assign to the ASP.NET5-related git repository, such as executing the following command:

brew install dnvm

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

source dnvm.sh

After installation of the above DNVM, 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: This is only installed DNVM, and does not install any version of DNX, to install DNX, you can run DNVM or DNVM help to find the relevant command, the specific command is as follows:

dnvm upgrade [-x86][-x64] [-svr50][-svrc50] [-g|-global] [-proxy <ADDRESS>]
    1. Install the latest version of DNX from your feed source
    2. To set a default alias for an installed DNX
    3. Add the Dnx bin to the user in the PATH environment variable
    4. -g|-global is installed in the global (other users can also use)
    5. -f|-force Force Update to the latest version (even if the latest version is already installed)
    6. -proxy Use a specific address as a proxy when accessing a 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 version of DNX from the feed source
    4. Add the Dnx bin to the PATH environment variable in the current command line
    5. -p|-persistent Adding the Dnx bin to the system PATH environment variable
    6. -a|-alias setting aliases for DNX of the specified installation
    7. -g|-global Installation in the global context
    8. -f|-force Force 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 the Dnx bin to the PATH environment variable in the current command line
    2. None removes the Dnx bin from the PATH environment variable of the current command line
    3. -p|-persistent adding the Dnx bin to the system PATH environment variable
    4. -g|-global combination using-p to modify the user path to the system path
dnvm list //列出所有已安装的DNX版本dnvm alias //列出所有定义了别名的DNX版本dnvm alias <alias> // 显示定义了别名的DNX名称dnvm alias <alias> <semver> [-x86][-x64] [-svr50][-svrc50] //给指定的DNX版本设置别名
DNU command and Feed source configuration for managing assemblies

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

dnu restore: Queries all of the program's dependent packages and downloads them all to the packages directory, which downloads the entire dependency package and other dependent packages on which the dependent packages 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 will create the following directory structure:

    output/    output/packages    outpot/appName    output/commandName.cmd
    1. packagesThe directory contains the packages that are required for all applications.
    2. appNameThe directory contains the code for all applications, and if other artifacts are referenced, the other artifacts referenced will also create the siblings of their respective projects, that is, the resulting directory and the appname sibling.
    3. publishcommand, will be project.json in the commands node in the various commands, generate a response command-line file, such as the Web command in commands, we can dnx web run it by (format: dnx <command> ).

Since Dnu uses the NuGet command internally for the management of the package, it is necessary to properly configure the NuGet feed source, and the current ASP. NET 5 related packages are all on the myget feed, so we need to add this feed to work properly. 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 up directly through the tools--> options--> Nuget package manager--> package sources, such as the following:

Also note that the address of the above feed is the daily build of Asp.net5, and if you want to use a stable milestone version (such as 1.0.0_ALPHA4), you will need to use the following address https://www.myget.org/F/aspnetmaster/api/v2/ .

Web Server Support

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

Microsoft.AspNet.Loader.IIS (Helios)

This server is used to load the ASP.NET5 program on IIS to integrate with the IIS process while bypassing the System.Web performance gains that can support Windows authentication, static file access, and so on. The principle is to make a bridge between IIS and NDX.

Microsoft.AspNet.Server.WebListener (Weblistener)

By Microsoft.AspNet.Hosting loading programs, services, work role, and so on outside of IIS, the server runs directly on the HTTP. SYS core driver, consuming only a little performance, from which you can benefit from port sharing, Windows authentication, and more.

Microsoft.AspNet.Server.Kestrel (Kestrel)

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

Reference content
    1. Https://github.com/aspnet/Home/wiki/DNX-structure
    2. Https://github.com/aspnet/Home/wiki/Command-Line
    3. Https://github.com/aspnet/Home/wiki/Version-Manager
    4. Https://github.com/aspnet/Home/wiki/Package-Manager
Synchronization and recommendations

This article has been synchronized to the Catalog index: Interpreting ASP. & MVC6 Series

Interpreting ASP 5 & MVC6 Series (4): Core technology and environment configuration

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.