使用在Inno Setup脚本中的Inno Setup编译器命令行上指定的路径/值 [英] Using path/value specified on Inno Setup compiler command-line in Inno Setup script
问题描述
我想将路径(通过命令行arg /D
传递给脚本编译器)传递给我的可执行文件,以使我的脚本使用GetFileVersion
确定应用程序版本号,但是我的语法不正确.如何将参数传递给GetFileVersion
?
错误是:输入文件中的字符非法:#"(0x23)
I want to pass a path (via command line arg /D
to the script compiler) to my executable to let my script determine the application version number using GetFileVersion
, but my syntax isn't correct. How do I pass an argument to GetFileVersion
?
The error is: Illegal character in input file: '#' (0x23)
#define srcpath SOURCEPATH
#define ApplicationVersion GetFileVersion(#srcpath)//error here!!!!!!
[Setup]
AppVersion={#ApplicationVersion}
[Files]
Source: "MyDllTesting.dll"; Flags: dontcopy
Source: "{srcpath}MyApplication1.exe"; DestDir: "{app}\MyApplication1"
推荐答案
首先,SOURCEPATH
是SOURCE_PATH.
First, SOURCEPATH
is a Inno Setup preprocessor predefined variable, so you need to use another name for your command-line "variable". I'll be using SOURCE_PATH
.
第二,正确的语法是:
#define ApplicationVersion GetFileVersion(SOURCE_PATH)
(即无哈希)
为什么我的答案中没有散列?
为什么预处理程序在#include指令中的行为与在[文件]部分的Inno Setup脚本中的行为不同
Why no hash, is covered in my answer to
Why preprocessor behaves differently in #include directive then in [Files] section Inno Setup script
虽然原因基本相同,但为什么在此处SOURCEPATH
之前不使用哈希:
Though the reason is basically the same, why you use no hash before SOURCEPATH
here:
#define srcpath SOURCEPATH
相反,您缺少[Files]
节条目中的哈希.正确的语法是:
On the contrary you are missing the hash in the [Files]
section entry. The correct syntax is:
[Files]
Source: "{#srcpath}MyApplication1.exe"; DestDir: "{app}\MyApplication1"
并且无需定义srcpath
变量. SOURCE_PATH
也是变量.因此,您可以直接在任何表达式中使用它:
And there's no need to define srcpath
variable. SOURCE_PATH
is variable too. So you can use it directly in any expression:
#define ApplicationVersion GetFileVersion(SOURCE_PATH)
[Files]
Source: "{#SOURCE_PATH}MyApplication1.exe"; DestDir: "{app}\MyApplication1"
这篇关于使用在Inno Setup脚本中的Inno Setup编译器命令行上指定的路径/值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!