Native Image Generator Tool

We can always find ourselves in a situation where we need to deploy .NET Win Forms based application on very low end computers which fit the bare minimum hardware requirements to run .NET applications

ITPro Today

November 10, 2004

5 Min Read
ITPro Today logo in a gray background | ITPro Today

We can always find ourselves in a situation where we need to deploy .NET Win Forms based application on very low end computers which fit the bare minimum hardware requirements to run .NET applications. This requires us developers to try and make our code as optimized as possible. Besides that, there is one more method, which can be employed to improve the performance of the application, which is by using the Ngen.exe tool.

            As we all know that a C# or VB.NET code when compiled is converted into MSIL (Microsoft Intermediate language). This MSIL code is recompiled dynamically into native language and executed.

            The Native Image generator tool creates a native image of a managed .NET assembly and stores it in the Native Image Cache, which is an area in the Global Assembly Cache on the local machine. The CLR detects that a native image exists for a particular assembly and loads it instead, every time the assembly is needed. This results in the assembly loading and executing faster as that assembly does not need to be re compiled into native code.

            Whenever Ngen.exe is used, the resultant native image depends on the following factors:

·        Version of the .NET Framework.

·        CPU

·        Version of the operating system.

·        Identities of all the assemblies involved.

·        Security

Hence when an assembly is executed, the CLR first looks for a native image based on the above factors, if not found, it reverts to JIT runtime compilation.

 

We can use the following command to create a native image

 

ngen WinApp.exe

 

It is quite obvious that WinApp.exe would reference other managed assemblies. We will have to run the tool separately for all referenced assemblies.

 

There are various other command line options that can be used. Given below are some of the important options.

 

Option

Description

/show

Displays all the assembly for which the native image exists

/delete

Deletes the native image of the assembly

/help

Displays command syntax and all options

/debug

Generates a native image to be used by the debugger in debugging mode

 

 

 

Read more about:

Microsoft
Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like