简体   繁体   中英

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 .

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.

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. 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:

Parameters are processed in order. makensis /Ddef script.nsi is not the same as makensis 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.

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

GetParameters returns the parameters passed to the installer on the end-users system, not the compiler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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