73

I am using Inno Setup to generate the installer of my application. How can set the version number of the setup.exe (VersionInfoVersion) generated by Inno to match with the version number of my application automatically? Now every time I deploy a new version of my application I need to update the version number manually.

Now I'm doing this:

[Setup]
VersionInfoVersion=1.2.2.0 //writing the value manually

I want something like this:

[Setup]
VersionInfoVersion={Get the version of my app}
AndyUK
  • 3,933
  • 7
  • 42
  • 44
Salvador
  • 16,132
  • 33
  • 143
  • 245

7 Answers7

108

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}
Georg W.
  • 1,292
  • 10
  • 27
RRUZ
  • 134,889
  • 20
  • 356
  • 483
  • 7
    Oh it seems I needed to put in the complete path to my exe... not just the name of the exe as in the example. – NickG Jun 03 '13 at 10:34
  • 4
    why isn't it possible to use `#define ApplicationVersion GetFileVersion({#ApplicationName})` ? – SAAD May 24 '16 at 09:30
  • 2
    @NickG: relative path is also sufficient – Jacek Krawczyk Oct 07 '16 at 13:51
  • 5
    @SAAD: it should work: `#define ApplicationVersion GetFileVersion(ApplicationName)` – Jacek Krawczyk Oct 07 '16 at 13:55
  • 10
    In case you have relative folder specified separately, the correct syntax would be: `#define MyAppVersion GetFileVersion(MyAppSourceFolder + '\' + MyAppExeName)`. It is important to remember that `{#var}` syntax doesn't seem to work here. – wpfwannabe Dec 25 '17 at 14:01
17

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);
Malick
  • 6,252
  • 2
  • 46
  • 59
6

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>
Jens A. Koch
  • 39,862
  • 13
  • 113
  • 141
4

I had some problems with getting this to work, so just contributing my solution.

app.iss:

[Setup]
#include "Config.txt"

#define AppVersion GetFileVersion("Input\" + AppExec)


AppName={#AppName}
AppVersion={#AppVersion}

Config.txt:

#define AppName "App"
#define AppExec "App.exe"
JanRK
  • 147
  • 1
  • 5
4

As others have mentioned, the GetFileVersion or GetStringFileInfo preprocessor functions can be used for that.

Some important info, improvements and helpful additions:

  • You can either use an absolute path to the exe, or a path relative to the .iss file
  • You can include existing defines in your statement by just writing their name, and concatenate defines with the + operator:
    #define MyAppPath "..\Win32\Release\" + MyAppExeName
  • If you want you can easily remove parts of the version number from the right by using the function RemoveFileExt, e. g. convert 3.1.2.0 to 3.1.2:
    #define MyAppVersion RemoveFileExt(GetFileVersion(MyAppPath))
  • You can use the defines MyAppExeName and MyAppPath in the subsequent options like Messages, Files or Icons

Working example:

#define MyAppName "Application Name"
#define MyAppExeName "Application.exe"        
#define MyAppPath "..\Win32\Release\" + MyAppExeName
#define MyAppVersion RemoveFileExt(GetFileVersion(MyAppPath))

[Setup]
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppVerName={#MyAppName} {#MyAppVersion}
VersionInfoVersion={#MyAppVersion}
OutputBaseFilename={#MyAppName}-{#MyAppVersion}-Windows

...

[Messages]
SetupWindowTitle=Setup - {#MyAppName} {#MyAppVersion}

...

[Files]
Source: {#MyAppPath}; DestDir: "{app}"; Flags: ignoreversion; Tasks: desktopicon

...

[Icons]
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Flo
  • 219
  • 2
  • 10
2

In my case, I would like to define the version string from a file. I don't have an EXE, since my installer is packing an embedded Python program. So I define the version number in a one-line text file like such (this is created from a git tag statement beforehand):

..\Build\app_version.txt:
v1.2.1

In the Inno Setup, I used a pre-processor define statement to set the version throughout the text.

#define VerFileNum FileOpen("..\Build\app_version.txt")
#define MyAppVersion Trim(StringChange(FileRead(VerFileNum),"v",""))

Here, I used Trim() and StringChange() to remove the leading "v" and trailing spaces from the string. Later in the setup section, the AppVersion value can be set using the pre-processor definition:

[Setup]
AppVersion={#MyAppVersion}

The Inno Setup pre-processor has quite an extensive set of functions already defined: Inno setup pre-processor functions

RexBarker
  • 1,456
  • 16
  • 14
1

After quite some time trying other methods, the way it worked for me was to use a relative path (I have the .iss file in a folder and the EXE file two levels above).

; Extract File Version from EXE
#define MyAppVersion GetFileVersion("..\..\Release\CSClave.exe")
cdsaenz
  • 520
  • 1
  • 10
  • 15