How do I automatically set the version of my Inno Setup installer according to my application version?

前端 未结 6 1397
清歌不尽
清歌不尽 2020-12-02 08:43

I am using Inno Setup to generate the installer of my application. How can set the version number of the setup.exe (VersionInfoVersion) generated by Inno to mat

6条回答
  •  一个人的身影
    2020-12-02 09:12

    As others have mentioned, the GetFileVersion or GetStringFileInfo preprocessor functions can be used for that.

    Some important info, improvements and helpful additions:

    • You can either use an absolute path to the exe, or a path relative to the .iss file
    • You can include existing defines in your statement by just writing their name, and concatenate defines with the + operator:
      #define MyAppPath "..\Win32\Release\" + MyAppExeName
    • If you want you can easily remove parts of the version number from the right by using the function RemoveFileExt, e. g. convert 3.1.2.0 to 3.1.2:
      #define MyAppVersion RemoveFileExt(GetFileVersion(MyAppPath))
    • You can use the defines MyAppExeName and MyAppPath in the subsequent options like Messages, Files or Icons

    Working example:

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

提交回复
热议问题