本文介绍了在Inno Setup中使用Define和Constant的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Inno Setup中的#define有疑问.我已经进行了设置,确定谁可以很好地工作,并且如果我需要做一些修改,我正在考虑应用程序的未来.例如,如果我更改版本(主要版本,次要版本,内部版本,补丁程序...),则我不想每次都更改所有行(如注册表).

I've a question about the #define in Inno Setup. I've make a setup who's working well and i'm thinking of the future of app if i have some modification to do. For example, if i change the version (Major, Minor, Build, Patch,...) i doesn't want to change all the line (like Registry) at each time.

所以我尝试做这样的事情:

So i try to make something like that :

#define MyAppMajor "5"
#define MyAppMinor "5"
#define MyAppBuild "1"
#define MyAppPatch "1"

...

[Files]
Source: "D:\ProgramFiles\..."; DestDir: "{app}\Program\{MyAppMajor}.{MyAppMinor}\"; Flags: ignoreversion;

[Registry]
Root: "HKLM32"; Subkey: "Software\program\"; ... ; ValueData: "{MyAppMajor}.{MyAppMinor}.{MyAppBuild}.{MyAppPatch}";

但是无法编译,它说:

"未知常量"MyAppMajor".如果要嵌入单个"{"而不是常量,请使用两个连续的"{"字符"..

是否可以执行类似的操作来进行版本控制或其他常量?

Is there a way to do something like that for versionning or another constant ?

推荐答案

您错过了使用#字符(或 #emit ,是该版本的较长版本),用于将已定义的变量内联到脚本中,例如:

You missed to use the # char (or #emit, which is the longer version of the same), that is used to inline a defined variable into the script, e.g.:

#define MyAppMajor "5"
#define MyAppMinor "5"
#define MyAppBuild "1"
#define MyAppPatch "1"

[Files]
...; DestDir: "{app}\Program\{#MyAppMajor}.{#MyAppMinor}\"; Flags: ignoreversion;

[Registry]
...; ValueData: "{#MyAppMajor}.{#MyAppMinor}.{#MyAppBuild}.{#MyAppPatch}";

如果缺少此常量,则编译器会期望(内置)名为MyAppMajorMyAppMinor等的常量,而这些常量不存在;这些常量不存在.因此是错误.

When missing this, the compiler expected (built-in) constants called MyAppMajor, MyAppMinor etc., whose doesn't exist; hence the error.

但是,您要复制的内容可能是Inno Setup中内置的,其 AppVersion 指令.这可能是有用的,例如结合从包含的文件版本信息中读取应用程序二进制文件的版本:

But, what you're trying to replicate is probably built-in in Inno Setup as the AppVersion directive. It might be useful e.g. in conjunction of reading the version of the application binary from its included file version information:

#define AppVersion GetFileVersion('C:\MyApp.exe')

[Setup]
...
AppVersion={#AppVersion}

这篇关于在Inno Setup中使用Define和Constant的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 06:07