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?
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?
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}
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.
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
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.
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\";
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...