Interpreting ASP 5 & MVC6 Series (4): Core technology and environment configuration
2015-05-17 19:21 by Uncle Tom, 11503 Read, 15 reviews, Favorites, compilation
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:
- 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.
- 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:
- 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.
- 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:
- 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.
- 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 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.ApplicationHost
is the application host provided by the running environment and has the following responsibilities:
project.json
the various dependent assemblies defined in the parse.
- Add one
ILoader
to to LoaderContainer
load the corresponding assembly from various places, such as source code, NuGet, Roslyn, and so on.
- 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:
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:
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>]
- Install the latest version of DNX from your feed source
- To set a default alias for an installed DNX
- Add the Dnx bin to the user in the PATH environment variable
- -g|-global is installed in the global (other users can also use)
- -f|-force Force Update to the latest version (even if the latest version is already installed)
- -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]
- | Install the specified DNX from the feed source
- Install the specified DNX from the local file system
- Latest Install the latest version of DNX from the feed source
- Add the Dnx bin to the PATH environment variable in the current command line
- -p|-persistent Adding the Dnx bin to the system PATH environment variable
- -a|-alias setting aliases for DNX of the specified installation
- -g|-global Installation in the global context
- -f|-force Force installation of the specified DNX (even if the version is already installed)
<semver>|<alias>|none [-x86][-x64] [-svr50][-svrc50] [-p|-persistent] [-g|-global]
- | Add the Dnx bin to the PATH environment variable in the current command line
- None removes the Dnx bin from the PATH environment variable of the current command line
- -p|-persistent adding the Dnx bin to the system PATH environment variable
- -g|-global combination using-p to modify the user path to the system path
<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
packages
The directory contains the packages that are required for all applications.
appName
The 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.
publish
command, 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:
<?xmlVersion= "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/" /> < Span class= "Hljs-tag" ></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
- 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
Interpreting ASP 5 & MVC6 Series (4): Core technology and environment configuration