我正在构建一个通常由我的同事安装的系统的安装程序,但是从一台目标机器到下一台机器可能有所不同,包括编译时要安装的文件的位置机。我想我可以在源代码中设置"gflag"(!define
}并在调用makensis.exe
(/D
)时覆盖它,但我无法做到甚至让我的安装程序认识到已经传递了/D
标志。
/h
标志后面有更多相关文档:
PS C:\> &"C:\Program Files (x86)\NSIS\makensis.exe" /h
Usage:
makensis [ option | script.nsi | - ] [...]
Options:
#...
/Ddefine[=value] defines the symbol "define" for the script [to value]
#...
我正在使用此NSIS代码:
!ifndef test
!define test Foo
!endif
Section
DetailPrint "${test}"
SectionEnd
我在PowerShell中编译安装程序:
&"C:\Program Files (x86)\NSIS\makensis.exe" "C:\path\to\test.nsi" /Dtest=Bar
在输出中,我看到了:
Command line defined: "test=Bar"
安装程序已成功创建,但在打印Foo
时会打印Bar
。如果我评论!define test Foo
,我会在编译时收到警告:
1 warning:
unknown variable/constant "{test}" detected, ignoring (C:\Mach4\Installer\test.nsi:6)
然后打印${test}
,表明gflag没有值。为什么它的值不是Bar
?
答案 0 :(得分:1)
按顺序解析命令行。在您的情况下,这意味着在解析/Dtest=Bar
之前解析脚本。试试这个:
"C:\Program Files (x86)\NSIS\makensis.exe" /Dtest=Bar "C:\path\to\test.nsi"