Click here to Skip to main content
Click here to Skip to main content
Go to top

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

Introduction

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.

Background

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

(innosetup_inst_folder)ngen/x86

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

(innosetup_inst_folder)ngen/x64.

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

Your distribution folder tree should be like:

(innosetup_distribution_folder) 
    \ gen
        \x86
        ngen.exe            <-- x86 version
        \x64
        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.

License

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

Share

About the Author

Fabrizio Stellato
Software Developer (Senior)
Italy Italy
Creator of:
Impulse Media Player http://impulsemediaplayer.codeplex.com
Audio Pitch & Shift http://audiops.codeplex.com
Ultimate Music Tagger http://umtagger.codeplex.com
Modern Log Viewer http://modernlogviewer.codeplex.com
Pitch Tuner http://pitchtuner.codeplex.com
Modern Audio Tagger http://modernaudiotagger.codeplex.com
Follow on   LinkedIn

Comments and Discussions

 
BugLegal? PinmemberJoel Lucsy3-Apr-14 5:07 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140926.1 | Last Updated 3 Apr 2014
Article Copyright 2014 by Fabrizio Stellato
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid