(1) Compile the program into an assembly.
After writing the code, we compile a DLL or EXE file, which is called an Assembly. The Assembly includes msil and metadata (metadata contains data such as classes, attributes, and relationships between classes ). Whether it is VB. NET or C #, the final generated Assembly includes msil and metadata.
(2) Compile msil code at cost.
Use the local image generator (ngen.exe) tool to compile msil into local code that can be executed locally and save it to the local image.
(3) What does the program do internally?
Every time we run the. NET program, CLR will immediately compile and execute the msil code. On idea, we can also use ngen.exe to generate local code for our Assembly, which can increase the startup speed of the program to a certain extent.
(4) Example
1. First, write a simple program and generate the Assembly. For details, see:
2. Open the. NET decompilation tool ildasm, such:
3. Open the generated assembly and check the intermediate language code (msil), for example:
As you can see, the code in the figure is the intermediate code of the program.
4. Now, let us compile the compiler code manually, open the. NET command line tool, and use the ngen.exe tool to compile our Assembly cost code, enter the command, and the absolute path of the ngen + Assembly, such:
No, the Code image has been compiled.
5. Finally, let's take a look at the generated local code image and enter ngen/show studymsil, such:
^_^ Have you seen it? This is our local code Image File