In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is the core technology of ASP.NET5 MVC6 and the method of environment configuration". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what is the core technology of ASP.NET5 MVC6 and the method of environment configuration"?
Asp.net 5 is the next generation of asp.net, which has been completely rewritten for cross-platform use. In the new version, Microsoft has introduced the following tools and commands: DNVM, DNX, DNU.
DNVM (.NET Version Manager): to implement cross-platform directories, Microsoft provides DNVM functionality. DNVM is the bottom content of ASP.NET. It is a set of Powershell scripts that start a specified version of the ASP.NET runtime environment, and can manage various versions of the ASP.NET runtime environment (DNX) and upgrade accordingly by using the Nuget tool at the same point in time on the same machine.
DNX (.NET Execution Environment): DNX is the running environment for ASP.NET programs to start and run ASP.NET programs. The running environment includes the compiler system, the SDK tool set and the Native CLR host environment. You can use DNVM to manage various versions of DNX, such as the dnvm list command to list all available DNX environments, while dnvm install 0.1-alpha-build-0446 can install a specified version of DNX to a .dnx folder, and you can find all installed versions of DNX in the% USERPROFILE%\ .dnx\ runtimes directory. Different operating systems have different versions of DNX.
Dnx.exe:dnx.exe is a command-line tool used to launch from the host environment (Self-Hosting). When using command-line code to start the program from the host environment, dnx is responsible for finding and calling the CLR Native Host,dnx command is the entry point of the entire running environment, you can use dnx run to start the program.
Dnu (DNX Utility): is a command-line package manager included in 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, such as automatically downloading custom assemblies in project.json for use.
DNX Architecture and its Operation principle
DNX is the core of the ASP.NET program, which follows the following two guidelines:
DNX should be self-contained, and DNX won't know which Core CLR package to use until it parses the application dependency tree, so DNX cannot load any CLR until it gets the parsing tree, except for the Roslyn compiler.
Dependency Injection (DI) runs through the whole 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 function of this layer is very simple, which is mainly used to find and call the CLR Native Host in Layer 1, and pass the system-related parameters to native host for later use. Currently, DNX.exe is used under Windows to handle this, and IIS also provides an intermediary (an AspNet.Loader.dll in the bin directory of the website) to forward requests to Native Host;, while Linux and Mac support this feature through their corresponding versions 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 the project precompiled assembly), which is where the managed code entry point of the Layer 2 layer can load the assembly.
-- appbase {path}: the directory saved by the program. The default is% CD%.
[ProgramName]: the name of the program in which the assembly (or dll with Programe::Main) is stored in the-- lib path. The default value is name in appbase\ project.json. In most cases, the name is the program host (Microsoft.Net.ApplicationHost) that contains the load chain. However, if your program contains an entry point (the Main method) and is compiled into the-- lib directory, you can use the name of the assembly as [ProgramName], which will 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. This layer has the following two responsibilities:
Start CLR, and which CLR to start depends on the version of CLR you choose. In the case of Core CLR, the layer loads coreclr.dll, configures and starts the runtime environment, and then creates an application domain (AppDomain) to run all managed code.
Invokes the entry point of managed code (Layer 2), and once the entry point of Native Host returns the thread, it cleans up and shuts down the thread of CLR, for example, unloading the application domain (AppDomain) and stopping the runtime environment.
Layer 2:Managed Entry Point
The Layer 2 layer (managed code portal) is the first layer for writing managed code, and its responsibilities are as follows:
Create a LoaderContainer that contains the required ILoaders, and the ILoader is responsible for loading the assembly based on the name of the assembly. If CLR needs an assembly, LoaderContainer uses its ILoader to parse the desired assembly.
From the path directory of-- lib, 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 in use, pass in the name of the assembly containing the entry point of the program as a parameter to [ProgramName], and the Layer 2 layer will call the assembly directly.
However, in other cases, an application host (Application host) is used to resolve the program's dependencies and start the running program. Microsoft.Net.ApplicationHost is the application host provided by the runtime environment and has the following responsibilities:
Parse the various dependent assemblies defined in project.json.
Add an ILoader to LoaderContainer to load the appropriate assembly from various places (such as source code, NuGet, Roslyn, and so on).
Invokes the entry point of the assembly and passes it to DNX.exe as the next parameter.
Layer 4:Application
This layer is the program developed by the developer that runs on top of the application host.
Environment configuration:
To configure DNX, the running environment of ASP.NET 5 programs, you first need to install and configure DNVM. Different operating systems install DNVM differently, so we'll explain it here.
Windows installation commands:
/ / you 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 Mac, first install the package manager Homebrew (http://brew.sh)) of the Mac system itself, and use the brew tap aspnet/k command to assign to the ASP.NET5-related git repository, such as the following command:
Brew install dnvm
This command will automatically download the latest DNX from ttps://www.nuget.org/api/v2. After downloading, 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 copies the dnvm file to the C:\ Program Files\ Microsoft DNX\ Dnvm directory and adds the C:\ Program Files\ Microsoft DNX\ Dnvm directory to the environment variable so that it can be used globally. Note: only DNVM is installed here, but no version of DNX is installed. To install DNX, you can find the relevant commands by running dnvm or dnvm help. The specific commands are as follows:
Dnvm upgrade [- x86] [- x64] [- svr50] [- svrc50] [- g |-global] [- proxy]
1. Install the latest version of DNX from the feed source
two。 Set a default (default) alias for the installed DNX
3. Add DNX bin to the user PATH environment variable
4. Murg |-global is installed globally (other users can also use it)
5.Musf |-force is forced to be updated to the latest version (even if the latest version has already been installed)
6.-proxy uses a specific address as a proxy when accessing a remote server
Dnvm install | latest [- x86] [- x64] [- svr50] [- svrc50] [- a |-alias] [- g |-global] [- f |-force]
1. Install the specified DNX from the feed source
two。 Mounts the specified DNX from the local file system
3.latest installs the latest version of DNX from the feed source
4. Add DNX bin to the path environment variable on the current command line
5. Murp |-persistent adds DNX bin to the system PATH environment variable
6. Mura |-alias sets an alias for the specified installation of DNX
7. Murg |-global is installed globally.
8.Musf |-force forces the specified DNX to be installed (even if this version is already installed)
Dnvm use | | none [- x86] [- x64] [- svr50] [- svrc50] [- p |-persistent] [- g |-global]
1. Add DNX bin to the path environment variable on the current command line
2.none removes DNX bin from the path environment variable on the current command line
3. Murp |-persistent adds DNX bin to the system PATH environment variable
4. Murg |-global is combined with-p to modify user PATH to system PATH.
Dnvm list / / list all installed DNX versions dnvm alias / / list all DNX versions with aliases defined dnvm alias / / display DNX names with aliases defined dnvm alias [- x86] [- x64] [- svr50] [- svrc50] / / set aliases for the specified DNX version
Manage the dnu command and feed source configuration of the assembly
When using the dnu command for package management, you usually use the following command:
Dnu restore: query all dependent packages of the program and download them all to the packages directory. This command downloads the entire dependent package and other dependent packages that these dependent packages depend on.
Dun install: this install command is used to download the specified package and add it to the program.
Dun publish: this command packages 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
The 1.packages directory contains the packages that all applications need.
The 2.appName directory contains code for all applications, and if other projects are referenced, other projects referenced will also create sibling directories for their respective projects, that is, the generated directories will be at the same level as AppName.
The 3.publish command will generate response command line files for various commands in the commands node in project.json, such as the web command in commands, and we can run it through dnx web (format: dnx).
Because dnu internally uses the Nuget command to manage the package, it is necessary to correctly configure the feed source of Nuget when using it. Currently, all ASP.NET 5-related packages are on myget feed, so we need to add this feed to run normally. This configuration information is managed in the% AppData%\ NuGet\ NuGet.config (or ~ / .config / NuGet/NuGet.config used by Mono under * nix) file under Windows. Examples are as follows:
Under VS2015, you can set it directly through Tools-- > Options-- > Nuget Package Manager-- > Package Sources. The example is as follows:
Also note that the address of the above feed is the daily build of asp.net5. If you want to use a stable milestone version (such as 1.0.0_alpha4), you need to use the address https://www.myget.org/F/aspnetmaster/api/v2/ below. Web Server support
Microsoft provides several Web server support when implementing DNX, which are as follows:
Microsoft.AspNet.Loader.IIS (Helios)
The server is used to load ASP.NET5 programs on IIS in order to integrate with IIS processes, while bypassing System.Web to bring performance improvement, and can support Windows authentication, static file access and other functions. The principle is to bridge between IIS and NDX.
Microsoft.AspNet.Server.WebListener (WebListener)
The server loads programs, services, work role and so on outside of IIS through Microsoft.AspNet.Hosting. It runs directly on the Http.Sys core driver and consumes only a little performance, from which it can benefit from port sharing, Windows authentication and other functions.
Microsoft.AspNet.Server.Kestrel (Kestrel)
The server loads and runs outside of IIS through Microsoft.AspNet.Server.Kestrel and is designed for cross-platform Web services (Windows, Mac, Linux, and so on).
At this point, I believe you have a deeper understanding of "what is the core technology of ASP.NET5 MVC6 and the method of environment configuration". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.