2
votes

I want to pass a path (via command line arg /D to the script compiler) to my executable to let my script determine the application version number using GetFileVersion, but my syntax isn't correct. How do I pass an argument to GetFileVersion? The error is: Illegal character in input file: '#' (0x23)

#define srcpath SOURCEPATH
#define ApplicationVersion GetFileVersion(#srcpath)//error here!!!!!!

[Setup]
AppVersion={#ApplicationVersion}

[Files]
Source: "MyDllTesting.dll"; Flags: dontcopy
Source: "{srcpath}MyApplication1.exe"; DestDir: "{app}\MyApplication1"
2

2 Answers

2
votes

First, SOURCEPATH is a Inno Setup preprocessor predefined variable, so you need to use another name for your command-line "variable". I'll be using SOURCE_PATH.


Second, the correct syntax is:

#define ApplicationVersion GetFileVersion(SOURCE_PATH)

(i.e. no hash)

Why no hash, is covered in my answer to
Why preprocessor behaves differently in #include directive then in [Files] section Inno Setup script

Though the reason is basically the same, why you use no hash before SOURCEPATH here:

#define srcpath SOURCEPATH

On the contrary you are missing the hash in the [Files] section entry. The correct syntax is:

[Files]
Source: "{#srcpath}MyApplication1.exe"; DestDir: "{app}\MyApplication1"

And there's no need to define srcpath variable. SOURCE_PATH is variable too. So you can use it directly in any expression:

#define ApplicationVersion GetFileVersion(SOURCE_PATH)

[Files]
Source: "{#SOURCE_PATH}MyApplication1.exe"; DestDir: "{app}\MyApplication1"
1
votes

From the docs on "Inno Setup Preprocessor: Command Line Compiler Execution" I could define a command line parameter called "MyCustomParam" by using /D option like this:

.\ISCC.exe /DMyCustomParam=MyParamValue "MySetupScript.iss"

and then I wrote my setup script like the following, which gets the value which was defined for the parameter on the command line:

[Setup]
AppName={#MyCustomParam}