简体   繁体   English

NSIS:如何使用参数来构建不同的安装程序

[英]NSIS: How to use a paramter to build different installer

I want to build my script differently depend how I set the paramter. 我想根据我设置参数的方式来不同地构建脚本。

I call my script like here: 我这样称呼我的脚本:

makensis test.nsi -DFLAG=10 or makensis test.nsi -DFLAG=8 . makensis test.nsi -DFLAG=10makensis test.nsi -DFLAG=8

I tried to use it as a paramter like here 我试图像这里一样使用它作为参数

${If} ${FLAG} == 10
   ...
${IfElse} ${FLAG} == 8
   ....
${Else}
    !error "Set the Flag."
${IfEnd}

But I still get only there error message. 但是我仍然只收到错误消息。

I tried also to use GetParamters from the documentation 4.12. 我还尝试使用文档4.12中的GetParamters

include FileFunc.nsh
!insertmacro GetParameters
!insertmacro GetOptions

${GetParameters} $R0
ClearErrors
${GetOptions} $R0 -DFLAG= $0
!echo $R0

But it only returns $R0 and not the value. 但是它只返回$R0 ,而不返回值。 What are the mistake or are there a besser strategy? 有什么错误,或者有什么策略?

First off, you must execute it as makensis -DFLAG=8 test.nsi because the parameters are parsed in same order as you pass them in. From the documentation: 首先,必须以makensis -DFLAG=8 test.nsi身份执行它,因为参数的解析顺序与传递它们的顺序相同。

Parameters are processed in order. 参数按顺序处理。 makensis /Ddef script.nsi is not the same as makensis script.nsi /Ddef . makensis /Ddef script.nsimakensis script.nsi /Ddef

Secondly, you cannot mix ${If} with !error because the former is a run-time instruction and the latter is a compile-time instruction. 其次,您不能将${If}!error混合使用,因为前者是运行时指令,而后者是编译时指令。

Use !if ${FLAG} = 8 or !ifdef FLAG . 使用!if ${FLAG} = 8!ifdef FLAG

GetParameters returns the parameters passed to the installer on the end-users system, not the compiler. GetParameters返回传递给最终用户系统而不是编译器上的安装程序的参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM