如何根据我的应用程序版本自动设置Inno Setup安装程序的版本?

时间:2011-06-27 20:44:51

标签: inno-setup

我正在使用Inno Setup生成应用程序的安装程序。如何设置Inno生成的setup.exe(VersionInfoVersion)的版本号自动匹配我的应用程序的版本号?现在每次部署新版本的应用程序时,我都需要手动更新版本号。

现在我正在这样做:

[Setup]
VersionInfoVersion=1.2.2.0 //writing the value manually

我想要这样的事情:

[Setup]
VersionInfoVersion={Get the version of my app}

7 个答案:

答案 0 :(得分:80)

您可以像这样使用Inno Setup预处理器GetFileVersion功能

#define ApplicationName 'Application Name'
#define ApplicationVersion GetFileVersion('Application.exe')
[Setup]
AppName={#ApplicationName}
AppVerName={#ApplicationName} {#ApplicationVersion}
VersionInfoVersion={#ApplicationVersion}

答案 1 :(得分:7)

使用a command line argument

执行此操作的另一种方法
[Setup]           
AppVersion={#MyAppVersion}

你只需从cmd调用你的脚本:

cd C:\Program Files (x86)\Inno Setup 5

iscc /dMyAppVersion="10.0.0.1" "C:\MyPath\MyScript.iss"

它在iss脚本中模拟#define MyAppVersion="10.0.0.1"

如果您使用的是CakeBuild,则可以将此参数作为

传递
 string CurrentVersion  = "10.0.0.1";
 InnoSetupSettings settings = new InnoSetupSettings();
 settings.Defines=   new Dictionary<string, string>
            {
            { "MyAppVersion", CurrentVersion },
            };
   InnoSetup("C:\MyPath\MyScript.iss", settings);

答案 2 :(得分:5)

如果你有一个纯粹的webinstaller,接受的解决方案不会起作用, 因为您根本没有使用application.exe来获取版本号。

我使用 Nant 和带有版本号属性的build.xml文件,在我重建innosetup安装程序之前,我手动碰撞。

我的* .iss文件包含一个特殊的令牌@ APPVERSION @,它被替换 在构建过程中使用版本号。这是通过应用过滤链的复制操作完成的,见下文。

InnoSetup脚本(* .iss)

// the -APPVERSION- token is replaced during the nant build process
#define AppVersion "@APPVERSION@"

nant build.xml:

<!-- Version -->
<property name="product.Name"           value="My Software"/>
<property name="version.Major"          value="1"/>
<property name="version.Minor"          value="2"/>
<property name="version.BuildNumber"    value="3"/>
<property name="product.Version" 
          value="${version.Major}.${version.Minor}.${version.BuildNumber}"/>

<!-- build task -->
<target name="bump-version"
        description="Inserts the current version number into the InnoScript.">
        <copy todir="${dir.Build}" overwrite="true">
            <fileset basedir="${dir.Base}/innosetup/">
                <include name="product-webinstaller-w32.iss"/>
                <include name="product-webinstaller-w64.iss"/>
            </fileset>
            <filterchain>
                <replacetokens>
                    <token key="APPVERSION" value="${product.Version}"/>
                </replacetokens>
            </filterchain>
        </copy>
</target>

答案 3 :(得分:2)

我遇到了一些问题,所以只需提供我的解决方案。

app.iss:

[Setup]
#include "Config.txt"

#define AppVersion GetFileVersion("Input\" + AppExec)


AppName={#AppName}
AppVersion={#AppVersion}

CONFIG.TXT:

#define AppName "App"
#define AppExec "App.exe"

答案 4 :(得分:2)

正如其他人提到的那样,可以使用GetFileVersionGetStringFileInfo预处理程序功能。

一些重要的信息,改进和有用的补充:

  • 您可以使用exe的绝对路径,也可以使用相对于.iss文件的路径
  • 您可以只写它们的名称就可以在语句中包含现有定义,然后使用+运算符将定义串联起来:
    #define MyAppPath "..\Win32\Release\" + MyAppExeName
  • 如果需要,可以使用功能RemoveFileExt从右侧轻松删除部分版本号。 G。将3.1.2.0转换为3.1.2:
    #define MyAppVersion RemoveFileExt(GetFileVersion(MyAppPath))
  • 您可以在随后的选项中使用定义MyAppExeNameMyAppPath,例如MessagesFilesIcons

工作示例:

#define MyAppName "Application Name"
#define MyAppExeName "Application.exe"        
#define MyAppPath "..\Win32\Release\" + MyAppExeName
#define MyAppVersion RemoveFileExt(GetFileVersion(MyAppPath))

[Setup]
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppVerName={#MyAppName} {#MyAppVersion}
VersionInfoVersion={#MyAppVersion}
OutputBaseFilename={#MyAppName}-{#MyAppVersion}-Windows

...

[Messages]
SetupWindowTitle=Setup - {#MyAppName} {#MyAppVersion}

...

[Files]
Source: {#MyAppPath}; DestDir: "{app}"; Flags: ignoreversion; Tasks: desktopicon

...

[Icons]
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"

答案 5 :(得分:1)

就我而言,我想从文件中定义版本字符串。我没有 EXE,因为我的安装程序正在打包一个嵌入式 Python 程序。所以我在这样的单行文本文件中定义版本号(这是从 git tag 语句预先创建的):

<块引用>

..\Build\app_version.txt:
v1.2.1

在 Inno Setup 中,我使用预处理器定义语句来设置整个文本的版本。

#define VerFileNum FileOpen("..\Build\app_version.txt")
#define MyAppVersion Trim(StringChange(FileRead(VerFileNum),"v",""))

在这里,我使用了 Trim()StringChange() 从字符串中删除了前导“v”和尾随空格。稍后在设置部分,可以使用预处理器定义设置 AppVersion 值:

[Setup]
AppVersion={#MyAppVersion}

Inno Setup 预处理器已经定义了相当广泛的函数集:Inno setup pre-processor functions

答案 6 :(得分:0)

尝试了很多方法之后,它为我工作的方式是使用相对路径(我在文件夹中有.iss文件,而在上面两层中有EXE文件)。

; Extract File Version from EXE
#define MyAppVersion GetFileVersion("..\..\Release\CSClave.exe")
相关问题