How do I automatically set the version of my Inno Setup installer according to my application version?

You can use the Inno Setup Preprocessor GetVersionNumbersString function like this

#define ApplicationName 'Application Name'
#define ApplicationVersion GetVersionNumbersString('Application.exe')
[Setup]
AppName={#ApplicationName}
AppVerName={#ApplicationName} {#ApplicationVersion}
VersionInfoVersion={#ApplicationVersion}

Another way to do it by using a command line argument :

[Setup]           
AppVersion={#MyAppVersion}

and you just call your script as follow from a cmd :

cd C:\Program Files (x86)\Inno Setup 5

iscc /dMyAppVersion="10.0.0.1" "C:\MyPath\MyScript.iss"

It emulate #define MyAppVersion="10.0.0.1" in the iss script.


If you are using CakeBuild, you can pass this argument as

 string CurrentVersion  = "10.0.0.1";
 InnoSetupSettings settings = new InnoSetupSettings();
 settings.Defines=   new Dictionary<string, string>
            {
            { "MyAppVersion", CurrentVersion },
            };
   InnoSetup("C:\MyPath\MyScript.iss", settings);

In case you have a pure webinstaller, the accepted solution won't work, because you simply won't have an application.exe to get the version number from.

I'm using Nant and a build.xml file with version number properties, which i manually bump, before i'm rebuilding the innosetup installers.

My *.iss files contain a special token @APPVERSION@, which is replaced with the version number during the build process. This is done via a copy operation with an applied filterchain, see below.

InnoSetup Script (*.iss)

// the -APPVERSION- token is replaced during the nant build process
#define AppVersion "@APPVERSION@"

nant build.xml:

<!-- Version -->
<property name="product.Name"           value="My Software"/>
<property name="version.Major"          value="1"/>
<property name="version.Minor"          value="2"/>
<property name="version.BuildNumber"    value="3"/>
<property name="product.Version" 
          value="${version.Major}.${version.Minor}.${version.BuildNumber}"/>

<!-- build task -->
<target name="bump-version"
        description="Inserts the current version number into the InnoScript.">
        <copy todir="${dir.Build}" overwrite="true">
            <fileset basedir="${dir.Base}/innosetup/">
                <include name="product-webinstaller-w32.iss"/>
                <include name="product-webinstaller-w64.iss"/>
            </fileset>
            <filterchain>
                <replacetokens>
                    <token key="APPVERSION" value="${product.Version}"/>
                </replacetokens>
            </filterchain>
        </copy>
</target>

Tags:

Inno Setup