Click here to Skip to main content
15,885,216 members
Articles / Installer
Tip/Trick

InnoSetup, optimize your application with ngen

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
3 Apr 2014CPOL1 min read 13.6K   9   1
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:

C++
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)


Written By
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
Win Log Inspector http://windowsloganalyzer.com/win-log-inspector/
Win Log Analyzer http://windowsloganalyzer.com/win-log-analyzer/

Comments and Discussions

 
BugLegal? Pin
Joel Lucsy3-Apr-14 5:07
Joel Lucsy3-Apr-14 5: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.