inno-setup

Using path/value specified on Inno Setup compiler command-line in Inno Setup script


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"

Solution

  • 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.

    Also the GetFileVersion was renamed to GetVersionNumbersString, so I'll be using the new name too.


    Second, the correct syntax is:

    #define ApplicationVersion GetVersionNumbersString(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 GetVersionNumbersString(SOURCE_PATH)
    
    [Files]
    Source: "{#SOURCE_PATH}MyApplication1.exe"; DestDir: "{app}\MyApplication1"