A native binary image for the current operating systems is generated by the Native Image Generator (Ngen.exe).
They are stored in a native image cache on the local computer.
It restores the code and data structures from the native image cache rather than generating them dynamically because it allows the assembly to load and execute faster.
By using the native images it will benefit the applications by improving their startup times.
.NET runtime will use the image after it is generated to run the code rather than from the hard disk.
Once an assembly is executed, the CLR first looks for a native image based on the above factors and if it is not found, it will revert to the JIT runtime compilation.
When compared to Native Image, MSIL code is loading slow because of JIT compilation and type-safety verification.
Usage of native image:
1.ngen install MyApp.exe
This command generates a native image for MyApp.exe which is located in the current directory, and it will install the image in the native image cache.
2.ngen install c:\project\MyApp.exe
This command generates a native image for MyApp.exe with the specified path.
Uninstall
- ngen uninstall c:\project\MyDll.dll /ExeConfig:c:\project\MyApp.exe
This command will uninstall the MyDll.dll.