如何将参数传递给 Inno Setup 命令行编译器?

发布于 2024-07-13 00:21:55 字数 139 浏览 8 评论 0原文

IS 新闻组建议使用 /D= 但使用版本 5.2.3 附带的 iscc.exe 时出现“未知选项:”错误。

那么在脚本中,如何使用命令行参数的值呢?

It was suggested in the IS newsgroup to use /D<variable>=<value> 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

方圜几里 2024-07-20 00:21:55

正如 MicSim 所说,你确实需要预处理器。 它包含在最新的 ISPack 中。 安装后,iscc 支持 /D

然后,您可以使用如下定义的值(假设您已完成 /DVERSION_NAME=1.23):

AppVerName=MyApplication v{#VERSION_NAME}

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}
森末i 2024-07-20 00:21:55

来自 Inno Setup 帮助文件:

Inno Setup 预处理器取代了
标准 Inno 安装命令行
由扩展编译器(ISCC.exe)
版本。 这个加长版
提供额外的参数来控制
Inno安装预处理器。

“额外参数”包括 /d 选项。

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.

等待我真够勒 2024-07-20 00:21:55

@Steven Dunn 的回答要点是用另一层抽象来解决问题:不要直接从终端调用 iscc your_script.iss,而是调用 your_script.ps1 -YourVar "value",处理开关,将 #define 写入 .iss 文件,然后然后使用iscc编译它。 这没有得到很好的阐述,而且我认为显示的用于解析命令行参数的函数没有增加太多价值。 不过,我还是在应得的地方给予赞扬。

正如@jdigital提到的,ISPP/d开关,但是ISPP不能直接从终端(据我所知)。 因此,@Steven Dunn 暗示的辅助脚本方法之类的东西是必要的。

您可以通过向现有 .iss 脚本添加占位符,然后相应地覆盖它们来实现此目的:

.iss 模板

; -- template.iss --

#define MyVar ""

...

.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

或如果您愿意,可以从 .ps1 脚本中运行 iscc 步骤。

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.

东京女 2024-07-20 00:21:55

/D 命令行参数对我来说非常有用。 如果您对语法感到困惑,我建议您调用 iscc \? 来查看帮助菜单,因为它在这里非常有用。

以下是我们创建安装程序的方法:

$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

然后在 ISS 中您可以像任何其他变量一样访问:

[Setup]
AppVersion={#VersionNo}

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

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\";
别低头,皇冠会掉 2024-07-20 00:21:55

如果要在 Inno Setup 中解析来自 [Code] 的命令行参数,请使用与此类似的方法。 只需从命令行调用 inno 脚本,如下所示:

C:\MyInstallDirectory>MyInnoSetup.exe -myParam parameterValue

然后您可以在任何需要的地方调用 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;

希望这可以帮助...

If you want to parse command line arguments from [Code] in Inno Setup, 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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文