2

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"
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Jana Andropov
  • 121
  • 11

2 Answers2

2

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"
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • If I use this: #define ApplicationVersion GetFileVersion(SOURCE_PATH). I get the following compile error: undeclared identifier SOURCE_PATH – Jana Andropov Jan 25 '19 at 17:30
  • Did you change the command-line argument to `/DSOURCE_PATH=C:\some\path\MyProg.exe`? – Martin Prikryl Jan 25 '19 at 17:35
  • Actually, I now see that you are using `srcpath`/`SOURCEPATH`/`SOURCE_PATH` inconsistently. For `GetFileVersion`, you use it as a full path to file name, while in `Source:` you use is a a path to folder only (and you concatenate it with filename `MyApplication1.exe`) --- it all looks like you are actually not passing `SOURCEPATH` on command-line at all (or incorrectly) - and it's actually not possible at all (as explained in my answer). And you actually use the `SourcePath` predefined variable (what is a path to a folder) -- There are way to many issues in your script :( – Martin Prikryl Jan 25 '19 at 17:41
  • It's the Compil32.exe compiler that's complaining about the variable SOURCE_PATH. – Jana Andropov Jan 25 '19 at 17:43
  • Isn't your question about `iscc.exe`? – Martin Prikryl Jan 25 '19 at 17:49
  • Does the use of arguments mean you can't use Compil32.exe? – Jana Andropov Jan 25 '19 at 17:58
  • No it doesn't. But let first solve your question with `iscc.exe`, before we get to other problems... – Martin Prikryl Jan 25 '19 at 18:03
  • Maybe I understand now --- What do you actually define on command-line? `srcpath` or `SOURCEPATH`? Doesn't you actually define `srcpath` and `#define srcpath SOURCEPATH` was your attempt to default to `SOURCEPATH` predefined variable when `srcpath` is not defined on the command-line? – Martin Prikryl Jan 25 '19 at 18:06
1

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}
Ulysses Alves
  • 2,297
  • 3
  • 24
  • 34