[英]How do you pass in parameters to the Inno Setup command line compiler?
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.在 IS 新闻组中建议使用 /D= 但使用 5.2.3 版本附带的 iscc.exe 我得到一个“未知选项:”错误。
Then in the script, how do you use the value of the command line parameter?那么在脚本中,如何使用命令行参数的值呢?
You do, as MicSim says, need the preprocessor. 正如MicSim所说,你需要预处理器。 It's included in the latest ISPack.
它包含在最新的ISPack中。 Once it's installed, iscc supports /D.
一旦安装,iscc支持/ D.
You can then use the values defined like this (assuming you'd done /DVERSION_NAME=1.23): 然后,您可以使用这样定义的值(假设您已完成/DVERSION_NAME = 1.23):
AppVerName=MyApplication v{#VERSION_NAME}
From the Inno Setup helpfile: 从Inno Setup帮助文件:
Inno Setup Preprocessor replaces the standard Inno Setup Command Line Compiler (ISCC.exe) by an extended version.
Inno Setup预处理器用扩展版替换了标准的Inno Setup命令行编译器(ISCC.exe)。 This extended version provides extra parameters to control Inno Setup Preprocessor.
此扩展版本提供了额外的参数来控制Inno Setup预处理器。
The "extra parameters" include the /d option. “额外参数”包括/ d选项。
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
. @Steven Dunn
的答案是通过另一层抽象来解决问题:不是直接从终端调用iscc your_script.iss
,而是调用your_script.ps1 -YourVar "value"
,处理开关,编写#define
到.iss
文件,然后用iscc
编译它。 This was not articulated well and I don't think the function shown to parse command line arguments added much value.这没有很好地表达出来,我认为显示的 function 解析命令行 arguments 没有增加多少价值。 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).正如
@jdigital
提到的, ISPP
有/d
开关,但ISPP
不能直接从终端运行(AFAIK)。 Hence, something like a secondary scripted approach hinted at by @Steven Dunn
is necessary.因此,
@Steven Dunn
暗示的类似辅助脚本方法的东西是必要的。
You can achieve this by adding placeholders to an existing .iss
script and then overwrite them accordingly:您可以通过向现有
.iss
脚本添加占位符然后相应地覆盖它们来实现此目的:
.iss
Template .iss
模板; -- template.iss --
#define MyVar ""
...
.ps1
Script .ps1
脚本#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.或者,如果您愿意,可以从
.ps1
脚本中运行iscc
步骤。
If you want to parse command line arguments from code in inno, then use a method similar to this. 如果要从inno中的代码解析命令行参数,请使用与此类似的方法。 Just call the inno script from the command line as follows:
只需从命令行调用inno脚本,如下所示:
C:\MyInstallDirectory>MyInnoSetup.exe -myParam parameterValue
Then you can call the GetCommandLineParam like this wherever you need it: 然后你可以在任何需要的地方调用GetCommandLineParam:
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... 希望这可以帮助...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.