Automated-build version number with WiX, Inno Setup, and VS2008

后端 未结 5 1031
-上瘾入骨i
-上瘾入骨i 2020-12-13 11:03

Basically what I need is an automated way to update the product version number in WiX (3.0 with Votive etc), and then get that version number into an Inno Setup \"bootstrapp

5条回答
  •  无人及你
    2020-12-13 11:33

    Some sample code as promised. This should be enough to get you started.

    The following JavaScript can be used to create an InnoSetup iss file containing the version number. The actual file will look like this:

    VersionInfoVersion=1.2.3.12345
    AppVerName=My App v1.2.3.12345
    

    The main Inno Setup script will include this file by adding the following to the end of the [Setup] section:

    [Setup]
    AppId={{...}}
    ...
    
    #include "version.iss"
    

    Here is the JavaScript (this would be saved as a separate file - version.js for example):

    createInnoSetupIncludeFile("My App", 1, 2, 3, 12345, "version.iss");
    
    function createInnoSetupIncludeFile(appName, verMajor, verMinor, verSubMinor, buildNumber, headerFileName)
    {
        var versionString = verMajor + "." + verMinor + "." + verSubMinor + "." + buildNumber;
        var fileSystemObject = WScript.CreateObject("Scripting.FileSystemObject");
        var fileObject = fileSystemObject.CreateTextFile(headerFileName, true);
        fileObject.WriteLine("VersionInfoVersion=" + versionString);
        fileObject.WriteLine("AppVerName=" + appName + " v" + versionString);
        fileObject.Close();
        fileObject = null;
        fileSystemObject = null;
    }
    

    You could tweak this script to create the version.iss file in a different folder.

    Finally you need to execute the JavaScript - the best place would be in the Pre-Build Event of your Visual Studio project. Add the following:

    cscript version.js //NoLogo
    

    You would need to change this to also build a Wix compatible include file. I used to do this, but dumped Wix in favour of Inno Setup, so I don't have this code to hand. There is a mechamism for a Wix script though, so that should point you in the right direction - the concept is the same - generate a text file that defines the version number and then include it.

    Hope this helps.

提交回复
热议问题