Inno Setup constants and parameters [duplicate] - inno-setup

This question already has answers here:
Passing in version number to Inno Setup compiler
(3 answers)
Closed 2 years ago.
I'm trying to add a parameter to my setup file, with a default value.
In this case I get a compile error at
OutputBaseFilename=MyApp {param:Version|{#MyAppVersion}} Setup
Saying:
Value of [Setup] section directive "OutputBaseFilename" is invalid
Shortened reference code:
#define MyAppName "My App"
#define MyAppVersion "1.7.24"
[Setup]
AppName={#MyAppName}
AppVersion="{param:Version|{#MyAppVersion}}"
DefaultGroupName=VHStudio
OutputBaseFilename=MyApp {param:Version|{#MyAppVersion}} Setup
SetupIconFile={#PathToRepoRoot}\Development\VHS\VHSStudio\media\logo.ico
[Icons]
Name: "{group}\VHStudio {param:version|MyAppVersion}"; Filename: "{app}\VHStudioApp.EXE"; WorkingDir: "{app}"
Name: "{group}\Uninstall VHStudio"; Filename: "{app}\unins000.exe"; WorkingDir: "{app}"
Name: "{userdesktop}\{#MyAppName}"; Filename: "{app}\VHStudioApp.EXE"; Tasks: desktopicon
I'm guessing I'm using the constant wrong?
The Strange thing is that I do
AppVersion="{param:Version|{#MyAppVersion}}"
Without any errors...

Based on the comment from Martin. Suggesting to take a look at Passing in version number to Inno Setup compiler.
Turns out I overcomplicated things. You can easily pass parameters to the compiler for pre-processor variables. In my situation MyAppVersion.
What I did in Inno Setup:
#ifndef MyAppVersion
#define MyAppVersion "1.7.24"
#endif
And when compiling it looks like this:
ISCC.exe myProg.iss /DMyAppVersion=1.7.14

Related

How to control addition of file in Inno Setup 6 script using the presence of a substring in a defined string

I have two executables which do the same thing, but one is built to target a DEV environment, and the other a PROD environment.
my-app-dev.exe
my-app-prod.exe
A VERSION parameter is always passed into the Inno build script which contains the build version in one of the following two formats:
"1.0.0"
"1.0.0-DEV"
In the [Files] section, how can I include the my-app-dev.exe if the current value of VERSION contains the DEV suffix, but include the my-app-prod.exe if not?
I figured a Check parameter would be the way to resolve this, but I can't even get the simplest case to work.
For example, the following adds the file to the build despite the Check function clearly returning False.
[Files]
Source: "my-app-dev.exe"; DestDir: {app}; Check: ShouldIncludeDev
function ShouldIncludeDev: Boolean;
begin
Result := False;
end;
Perhaps I must be missing something fundamental here...
Based on this answer (Inno Setup IDE and ISCC/ISPP passing define) you could do this:
Pass the value via command line parameter:
/DargDEV="DEV"
In your [Files] section you can then do this:
#ifdef argDEV
Source: "my-app-dev.exe"; DestDir: {app};
#else
Source: "my-app-prod.exe"; DestDir: {app};
#endif
Notes
It uses the #ifdef pre-processor directive.

Constant defined using Inno Setup preprocessor #define is not recognised in ExpandConstant

I'm trying to set up an install file that (optionally) installs .NET 5 if it's not already installed.
However, I'm having trouble defining the version of .NET to install in a constant.
My script is set up like this
#define DotNetVersion "5"
...
[Tasks]
Name: "dotnet"; Description: "{cm:DotNet}"; GroupDescription: "{cm:Prerequisites}"
...
[Files]
Source: "..\Dependencies\{#DotNetInstallFile}"; DestDir: {tmp}; \
Flags: deleteafterinstall; AfterInstall: InstallDotNet; \
Check: NetNotInstalled(ExpandConstant('{DotNetVersion}')); Tasks: "dotnet"
When I try running the resulting install file I get the following error:
Internal error: Expression error 'Internal error: Unknown constant "DotNetVersion"'
The function NetNotInstalled works correctly if I replace ExpandConstant('{DotNetVersion}') with '5', but I want to easily be able to change this without modifying more than the defined constants.
I don't get what's wrong here. The Inno Setup docs state that this should be valid.
Using the same constant for any other function seems to work flawlessly.
A variable defined using Inno Setup preprocessor is not Inno Setup constant. Calling ExpandConstant function on it has no effect.
To expand preprocessor variable (or any expression), you can use {#VariableOrExpression} syntax. It's an inline preprocessor directive call, where, when no directive is explicitly specified, the emit is implied. So the {#VariableOrExpression} is the same as {#emit VariableOrExpression}. And as every preprocessor construct, it's evaluated on compile time (contrary to ExpandConstant).
You actually do that correctly already with {#DotNetInstallFile}, so do the same with DotNetVersion:
Source: "..\Dependencies\{#DotNetInstallFile}"; \
DestDir: {tmp}; Flags: deleteafterinstall; AfterInstall: InstallDotNet; \
Check: NetNotInstalled('{#DotNetVersion}'); Tasks: "dotnet"
See also How to use variables \ macros with Inno Setup?

UTF-8 characters not displaying correctly in Inno Setup

I've seen a couple of other threads about this but I've spent a while trying to get it sorted to no avail.
Here's a generic version of my .iss file:
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define AppName "MyApp"
#define CompanyName "MyCompany"
#define FileName "File Name"
#define AppExeName "App Exe.exe"
#define AppIcon "..\icon.ico"
#define AppId "app.id"
#define AppURL "mywebsite"
#define AppSrcDir "path\to\app\directory"
#define AppTargetDir "{userappdata}\" + CompanyName + "\" + AppName
#define AppVersion GetFileVersion(AppSrcDir + "\" + AppExeName)
#define AppPublisher "Publisher"
#define LaunchMessage "Launch Message"
#define AppProtocol "protocol"
#define OutputDir "path\to\output"
#define SetupFilename FileName + "-setup-" + AppVersion
#define SetupImage "..\setup.bmp"
#define InstallerMessage "Some message with a German character - ö"
[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AllowCancelDuringInstall=no
AppId={#AppId}
AppName={#AppName}
AppVersion={#AppVersion}
AppVerName={#AppName} {#AppVersion}
AppPublisher={#AppPublisher}
AppPublisherURL={#AppURL}
AppSupportURL={#AppURL}
AppUpdatesURL={#AppURL}
DefaultDirName={#AppTargetDir}
DefaultGroupName={#CompanyName}
DisableDirPage=yes
DisableProgramGroupPage=yes
DisableReadyPage=yes
DisableReadyMemo=yes
OutputDir={#OutputDir}
OutputBaseFilename={#SetupFilename}
PrivilegesRequired=lowest
SetupIconFile={#AppIcon}
SignTool=signtool
Compression=lzma/ultra64
SolidCompression=yes
WizardSmallImageFile={#SetupImage}
UninstallDisplayIcon={app}\{#AppExeName}
[InstallDelete]
Type: filesandordirs; Name: {#AppTargetDir}
[Languages]
Name: de; MessagesFile: "compiler:Languages\German.isl"
[Files]
Source: "{#AppSrcDir}\*"; DestDir: "{app}"; Flags: recursesubdirs
Source: "path\to\other\installers\win32\*"; DestDir: "{app}\redist";
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
[Icons]
Name: "{group}\{#AppName}"; Filename: "{app}\{#AppExeName}"; WorkingDir: "{app}";
Name: "{commondesktop}\{#AppName}"; Filename: "{app}\{#AppExeName}"; WorkingDir: "{app}";
[Run]
FileName: "{app}\redist\installer.exe"; Parameters: "/S /v/qn"; WorkingDir: "{app}"; StatusMsg: "{#InstallerMessage}";
The problem I have is that it doesn't display the InstallerMessage text correctly. The ö character does not render correctly.
I am using the Unicode version of Inno Setup (with the "(u)").
I have seen some mentions of using a byte order mark but I haven't seen any examples. I tried converting the whole string using a UTF-8 encoder and added the byte order mark at the start but it didn't work. I'm completely stumped!
Make sure your .iss file uses UTF-8 encoding with BOM.
And of course, you need Unicode version of Inno Setup (the only version as of Inno Setup 6).
Was the string also used in Pascal Script code (what is not, mentioning it just for benefit of others, who may find this question), you also have to use Inno Setup 5.6.0 or later. Earlier versions did not support UTF-8 in Pascal Script.
Pascal Scripting changes:
Unicode Inno Setup: Unicode is now supported for the input source. For example, where before you had to write S := #$0100 + #$0101 + 'Aa'; you can now write S := 'ĀāAa'; directly. Also see the new UnicodeExample1.iss example script.
See also Inno Setup Unicode encoding issue with messages in ISS script.

Start Menu Folder as a Subdirectory - Inno Setup

I want to add a shortcut to my program in the start menu as follows:
MyAppPublisher\MyAppName\MyAppName
I have this in my script:
DefaultGroupName={#MyAppPublisher}
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
But the start menu folder is always:
MyAppName\MyAppName
Any ideas?
It's as easy as specifying this path in the Name parameter of the entry in the [Icons] section. Your current script creates a shortcut like MyAppPublisher\MyAppName, this one will do what you need:
#define MyAppName "MyAppName"
#define MyAppExeName "MyProg.exe"
#define MyAppPublisher "MyAppPublisher"
[Setup]
AppName={#MyAppName}
AppVersion=1.5
DefaultDirName={pf}\My Program
DefaultGroupName={#MyAppPublisher}
OutputDir=userdocs:Inno Setup Examples Output
[Files]
Source: "{#MyAppExeName}"; DestDir: "{app}"
[Icons]
; notice the full path to the created shortcut, {group} is taken from the Select
; Start Menu Folder page edit box (if shown), which is by default taken from the
; DefaultGroupName directive value; this start menu folder path is then followed
; by the tail of the shortcut path
Name: "{group}\{#MyAppName}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
If you want the group to be in a subfolder, you need to specify the sub folder.
The best way to do this is to append it to the end of the DefaultGroupName directive which will show the correct info in the setup wizard and allow the user to change it to as single folder or another location entirely if they wish.
DefaultGroupName={#MyAppPublisher}\{#MyAppName}
Note that the Start Menu in Windows 8 is not heirachical so any nesting won't be seen anyway.
Found it, my script suggested in the question was correct, for some reason I needed to generate a new GUID for the script for the changes to take effect

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

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}
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>
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"
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}"
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
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")

Resources