Click here to Skip to main content
13,253,863 members (65,583 online)
Click here to Skip to main content
Add your own
alternative version


8 bookmarked
Posted 3 Apr 2014

InnoSetup, optimize your application with ngen

, 3 Apr 2014
Rate this:
Please Sign up or sign in to vote.
Launch ngen.exe to optimize your application during installation


After my previous article about InnoSetup and .NET installer, I have decided to write another tip about ngen (Native Image Generator) for the .NET framework.


What is ngen ? MSDN says:

The Native Image Generator (Ngen.exe) is a tool that improves the performance of managed applications. Ngen.exe creates native images, which are files containing compiled processor-specific machine code, and installs them into the native image cache on the local computer. The runtime can use native images from the cache instead of using the just-in-time (JIT) compiler to compile the original assembly.

For more details, read the original article here

Using the code

Before editing the .iss file, locate ngen.exe in your Microsoft .NET installation directory.

The path should be {win}\Microsoft.NET.

Copy ngen.exe from path

Framework/(.NET ver)/

and place into your InnoSetup distribution folder under


Now do the same for ngen.exe under Framework64 folder and copy to


Innosetup binaries are prepared so it's time to edit innosetup iss file:

Your distribution folder tree should be like:

    \ gen
        ngen.exe            <-- x86 version
        ngen.exe            <-- x64 version 

Under [Files] section, just write this code:

Source: "{#MyDistFolder}\ngen\x86\ngen.exe"; DestDir: {tmp}; Flags: deleteafterinstall; Check: not Is64BitInstallMode; 
Source: "{#MyDistFolder}\ngen\x64\ngen.exe"; DestDir: {tmp}; Flags: deleteafterinstall; Check: Is64BitInstallMode;   

InnoSetup will copy the right ngen.exe into temp folder, according to the running architecture

Under [Run] section, write this

Filename: {tmp}\ngen.exe; Parameters: "install ""{app}\{#MyAppExeName}"""; StatusMsg: Optimizing performance for your system ...; Flags: runhidden

Installer will run the optimizer during installation AFTER all files (included exe) are copied, and a message "Optimizing performance for your system ..." will be shown.

At the end, we have our application with improved performances (at least Microsoft says so)

Points of Interest

We have explored some point of interests like x64 arch, temp installation directory and other stuff.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Fabrizio Stellato
Software Developer (Senior)
Italy Italy
Creator of:
Impulse Media Player
Audio Pitch & Shift
Ultimate Music Tagger
Modern Log Viewer
Pitch Tuner
Modern Audio Tagger
Win Log Inspector
Win Log Analyzer

You may also be interested in...


Comments and Discussions

BugLegal? Pin
Joel Lucsy3-Apr-14 6:07
memberJoel Lucsy3-Apr-14 6:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171114.1 | Last Updated 3 Apr 2014
Article Copyright 2014 by Fabrizio Stellato
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid