很多时候我们开发的软件本身已经有版本号文件了,那么如何在inno setup中使用这个版本号呢?
inno setup通过新建一个安装向导会产生一个版本号,需要通过自定义宏在[Setup]段中使用从文件中获取的版本号。
代码示例:
#define RetrieveVersion(str FileName) \
Local[0] = FileName, \
Local[1] = FileOpen(Local[0]), \
Local[2] = FileRead(Local[1]), \
Local[3] = FileRead(Local[1]), \
FileClose(Local[1]), \
Local[4] = Local[2]+"."+Local[3], \
Local[4]
#define MyAppName "hello demo"
#define MyAppVersion "1.5"
#define MyAppPublisher "my company"
#define MyAppURL "http://www.example.com/"
#define MyAppExeName "hello.exe"
#define VersionFile "D:\work\test\c++\hello demo\version.txt"
#define WinpcapExeName "WinPcap_4_1_3.exe"
#define NpcapExeName "npcap-1.10.exe"
#define MyAppUninstallRegistryKeyName "helloUninstall"
#define MyAppUninstallExeName "unins000.exe"
[Setup]
; 注意: AppId 的值是唯一识别这个程序的标志。
; 不要在其他程序中使用相同的 AppId 值。
; (在编译器中点击菜单“工具 -> 产生 GUID”可以产生一个新的 GUID)
AppId={{5EA1FAF6-B809-4278-AF75-280971EB4333}
AppName={#MyAppName}
AppVersion={#RetrieveVersion(VersionFile)}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName="C:\hello"
DefaultGroupName={#MyAppName}
AllowNoIcons=yes
OutputDir=D:\work\test\inno setup
OutputBaseFilename=hello-setup
Compression=lzma
SolidCompression=yes
版本号文件内容如下:
安装结果:
完整脚本下载: