What is Native Image Generator (Ngen.exe) and how does it work?


Ngen.exe (Native Image Generator) is a tool that creates native images, which are files containing compiled Processor-Specific machine code, and installs them into the native image cache on the local computer. It’s a tool that improves the performance of managed applications. In other words, rather than compiling the code dynamically using JIT on runtime, a full image of native compiled code is stored in cache while installing the application which leads to better performance as the assembly loads and execute faster.

The runtime can use native images from the cache instead of using JIT to compile the original assembly.
It not always necessary that Ngen.exe produces optimized code because it uses the current environments parameters which can change over a period of time. For instance, a code compiled in Windows XP environment will not be optimized to run under Windows 2008 server.
The following command is used in Visual Studio command line to install a full compiled native code in cache:
<input disabled="" style="font-size: 20px; width: 100%;" type="text" value=" ngen.exe install ” />

(1)

Leave a Reply

Your email address will not be published. Required fields are marked *