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

Inno setup 如何根据应用程序版本自动设置Inno安装程序的版本?,inno-setup,Inno Setup,我正在使用Inno安装程序生成应用程序的安装程序。如何设置Inno生成的setup.exe(versionInfo)的版本号,使其与我的应用程序的版本号自动匹配?现在,每次部署应用程序的新版本时,我都需要手动更新版本号 现在我要做的是: [Setup] VersionInfoVersion=1.2.2.0 //writing the value manually 我想要这样的东西: [Setup] VersionInfoVersion={Get the version of my app}

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

现在我要做的是:

[Setup]
VersionInfoVersion=1.2.2.0 //writing the value manually
我想要这样的东西:

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

您可以像这样使用Inno Setup预处理器
GetVersionNumbersString
函数

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

如果您有一个纯Web安装程序,那么接受的解决方案将无法工作, 因为您根本没有application.exe来获取版本号

我正在使用Nant和带有版本号属性的
build.xml
文件,在重建innosetup安装程序之前,我会手动添加这些属性

My*.iss文件包含一个特殊标记@APPVERSION@,该标记已被替换 在生成过程中使用版本号。这是通过应用过滤器链的复制操作完成的,请参见下文

InnoSetup脚本(*.iss)

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>

我在实现这一点时遇到了一些问题,所以请提供我的解决方案

app.iss:

[Setup]
#include "Config.txt"

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


AppName={#AppName}
AppVersion={#AppVersion}
Config.txt:

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

另一种方法是使用:

您只需从cmd调用脚本,如下所示:

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

iscc /dMyAppVersion="10.0.0.1" "C:\MyPath\MyScript.iss"
它模拟iss脚本中的
#定义MyAppVersion=“10.0.0.1”


如果正在使用,则可以将此参数作为

 string CurrentVersion  = "10.0.0.1";
 InnoSetupSettings settings = new InnoSetupSettings();
 settings.Defines=   new Dictionary<string, string>
            {
            { "MyAppVersion", CurrentVersion },
            };
   InnoSetup("C:\MyPath\MyScript.iss", settings);
string CurrentVersion=“10.0.0.1”;
InnoSetupSettings=新的InnoSetupSettings();
settings.Defines=新字典
{
{“MyAppVersion”,CurrentVersion},
};
InnoSetup(“C:\MyPath\MyScript.iss”,设置);

在尝试了一段时间的其他方法后,我的工作方式是使用相对路径(我在文件夹中有.iss文件,在上面两个级别有EXE文件)


正如其他人提到的,or预处理器函数可用于此目的

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

  • 您可以使用exe的绝对路径,也可以使用相对于.iss文件的路径
  • 只需写下现有定义的名称,就可以将其包含在语句中,并使用
    +
    运算符连接定义:
    #定义MyAppPath.。\Win32\Release\“+MyAppExeName
  • 如果需要,您可以使用函数
    RemoveFileExt
    ,从右侧轻松删除部分版本号。G将3.1.2.0转换为3.1.2:
    #定义MyAppVersion RemoveFileExt(GetFileVersion(MyAppPath))
  • 您可以在后续选项中使用定义
    MyAppExeName
    MyAppPath
    ,如
    消息
    文件
    图标
工作示例:

#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}"

在我的例子中,我想从一个文件中定义版本字符串。我没有EXE,因为我的安装程序正在打包一个嵌入式Python程序。因此,我在一行文本文件中定义了版本号,如下所示(这是从
git标记
语句中创建的):

..\Build\app\u version.txt:
v1.2.1

在Inno设置中,我使用预处理器define语句在整个文本中设置版本

#define VerFileNum FileOpen("..\Build\app_version.txt")
#define MyAppVersion Trim(StringChange(FileRead(VerFileNum),"v",""))
在这里,我使用
Trim()
StringChange()
从字符串中删除前导“v”和尾随空格。在后面的设置部分中,可以使用预处理器定义设置
AppVersion
值:

[Setup]
AppVersion={#MyAppVersion}

Inno Setup预处理器已经定义了相当广泛的一组功能:

哦,看来我需要输入我的exe的完整路径。。。不仅仅是示例中的exe名称。为什么不能使用
#define ApplicationVersion GetFileVersion({#ApplicationName})
?@NickG:相对路径也是sufficient@SAAD:它应该可以工作:
#定义ApplicationVersion GetFileVersion(ApplicationName)
如果您单独指定了相对文件夹,正确的语法应该是:
\define MyAppVersion GetFileVersion(MyAppSourceFolder+'\'+MyAppExeName)
。重要的是要记住,
{#var}
语法在这里似乎不起作用。
#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}"
#define VerFileNum FileOpen("..\Build\app_version.txt")
#define MyAppVersion Trim(StringChange(FileRead(VerFileNum),"v",""))
[Setup]
AppVersion={#MyAppVersion}