17

It was suggested in the IS newsgroup to use /D= but using the iscc.exe that came with version 5.2.3 I get an "Unknown option:" error.

Then in the script, how do you use the value of the command line parameter?

AlanKley
  • 4,592
  • 8
  • 40
  • 53

5 Answers5

24

You do, as MicSim says, need the preprocessor. It's included in the latest ISPack. Once it's installed, iscc supports /D.

You can then use the values defined like this (assuming you'd done /DVERSION_NAME=1.23):

AppVerName=MyApplication v{#VERSION_NAME}
Jon Bright
  • 13,388
  • 3
  • 31
  • 46
  • 4
    This is built-in to Inno Setup 5 now, so you don't have to download any extra packs. – Steve Hanov Aug 10 '12 at 14:44
  • 5
    This is not part of the documentation. Please include some helpful info here: http://www.jrsoftware.org/ishelp/index.php?topic=setupcmdline – vezenkov Jul 29 '15 at 05:22
5

From the Inno Setup helpfile:

Inno Setup Preprocessor replaces the standard Inno Setup Command Line Compiler (ISCC.exe) by an extended version. This extended version provides extra parameters to control Inno Setup Preprocessor.

The "extra parameters" include the /d option.

jdigital
  • 11,926
  • 4
  • 34
  • 51
  • Helpful to know, but `ISPP` is a `DLL`, not an `EXE`, so not sure how you can run that from the commandline. – adam.hendry Dec 07 '22 at 20:25
  • The answer is in the Inno documentation. Check out the section titled "Inno Setup Preprocessor: Command Line Compiler Execution". In short, /Dname=value defines a parameter that's made available to the preprocessor. – jdigital Dec 08 '22 at 05:07
  • Ah, I see. I'll have to look into this a little more. Thanks for following up! – adam.hendry Dec 18 '22 at 20:00
0

The point of the answer by @Steven Dunn is to solve the problem with another layer of abstraction: instead of calling iscc your_script.iss directly from the terminal, call your_script.ps1 -YourVar "value", process the switch, write a #define to the .iss file, and then compile it with iscc. This was not articulated well and I don't think the function shown to parse command line arguments added much value. However, I'm giving credit where credit is due.

As @jdigital mentioned, ISPP has the /d switch, but ISPP can't be run directly from the terminal (AFAIK). Hence, something like a secondary scripted approach hinted at by @Steven Dunn is necessary.

You can achieve this by adding placeholders to an existing .iss script and then overwrite them accordingly:

.iss Template

; -- template.iss --

#define MyVar ""

...

.ps1 Script

#requires -PSEdition Core

# create_iss_script.ps1

param(
    [Parameter(Mandatory=$true)][String]$MyVar,
    [Parameter(Mandatory=$true)][String]$OutFile,
)

$File = '.\template.iss'
$LineToReplace = '#define MyVar ""'
$NewLine = "#define MyVar ""${MyVar}"""

$FileContent = Get-Content -Path $File -Raw

$FileContent.Replace($LineToReplace, $NewLine) | Set-Content -Path $OutFile

Example Terminal Usage

PS> .\create_iss_script.ps1 -MyVar "HelloWorld!" -OutFile "helloworld.iss"
PS> iscc .\helloworld.iss

or run the iscc step from within your .ps1 script, if you prefer.

adam.hendry
  • 4,458
  • 5
  • 24
  • 51
0

The /D command line arg worked great for me. If you are struggling with the syntax I recommend just invoking iscc \? to see the help menu since it is pretty useful here.

Here is how we create our installer:

$ISCC = 'path/to/iscc.exe'
$ExternalDependency = 'random/path/to/external/dep'
# Make sure to quote escape /D filepath params
Start-Process -FilePath $ISCC -ArgumentList "/D""DepDir=$ExternalDependency"" VersionNo=1.1.0 ./myscript.iss""" -NoNewWindow

Then within the ISS you access like any other var:

[Setup]
AppVersion={#VersionNo}

[Files]
Source: "{#DepDir}\*"; DestDir: "{app}\external\";
-1

If you want to parse command line arguments from code in inno, then use a method similar to this. Just call the inno script from the command line as follows:

C:\MyInstallDirectory>MyInnoSetup.exe -myParam parameterValue

Then you can call the GetCommandLineParam like this wherever you need it:

myVariable := GetCommandLineParam('-myParam');

//==================================================================

{ Allows for standard command line parsing assuming a key/value organization }
function GetCommandlineParam (inParam: String):String;
var
  LoopVar : Integer;
  BreakLoop : Boolean;
begin
  { Init the variable to known values }
  LoopVar :=0;
  Result := '';
  BreakLoop := False;

  { Loop through the passed in arry to find the parameter }
  while ( (LoopVar < ParamCount) and
          (not BreakLoop) ) do
  begin
    { Determine if the looked for parameter is the next value }
    if ( (ParamStr(LoopVar) = inParam) and
         ( (LoopVar+1) < ParamCount )) then
    begin
      { Set the return result equal to the next command line parameter }
      Result := ParamStr(LoopVar+1);

      { Break the loop }
      BreakLoop := True;
    end

    { Increment the loop variable }
    LoopVar := LoopVar + 1;
  end;
end;

Hope this helps...

Cosmin
  • 21,216
  • 5
  • 45
  • 60
Steven Dunn
  • 195
  • 2
  • 2