Automated-build version number with WiX, Inno Setu

2019-01-21 20:28发布

问题:

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 "bootstrapper"

I pretty much have the process mostly automated, however version numbers still need to be updated manually which obviously isn't ideal, but I couldn't find how to pass in values to Inno Setup at compile time (and how to reference them), and in the WiX project I need to know how to reference the version number of a different project in the same solution in Visual Studio 2008

回答1:

No need to pass anything! You can simply let the InnoSetup Preprocessor read the version info straight from the binary's version resource, e.g.:

#define AppName "My App"
#define SrcApp "MyApp.exe"
#define FileVerStr GetFileVersion(SrcApp)
#define StripBuild(str VerStr) Copy(VerStr, 1, RPos(".", VerStr)-1)
#define AppVerStr StripBuild(FileVerStr)

[Setup]
AppName={#AppName}
AppVersion={#AppVerStr}
AppVerName={#AppName} {#AppVerStr}
UninstallDisplayName={#AppName} {#AppVerStr}
VersionInfoVersion={#FileVerStr}
VersionInfoTextVersion={#AppVerStr}
OutputBaseFilename=MyApp-{#FileVerStr}-setup

Before version 5.4.1 (2011-02-09) ISPP was not included in the default InnoSetup package. You had to download the InnoSetup Quick Start Pack: http://www.jrsoftware.org/isdl.php#qsp (thanks @Gwyn, for the update)



回答2:

You can get the ProductVersion for WiX from a file version in your package. Syntax is something like:

<Product Version="$(var.FileVersion.FileId)">

Or you can provide it on the command line to candle using the "-dVersionFromCommandLine=1.0.0.0" switch with syntax like:

<Product Version="$(var.VersionFromCommandLine)">

Either works in latest builds of WiX v3. Only the latter works on WiX v2.



回答3:

The way I do it is with a WSF script (I use JavaScript but you could use VBScript or even an SH script using Cygwin) that creates a header file containing definitions for the version numbers. You can use the Wix <include> statement to drag the version number in.

For Inno Setup I create a .iss file that contains the version number, which is #included into the main iss script.

I am at home but can post some sample code tomorrow if you like.

EDIT: I forgot to mention that I run the script that generates the files containing the build number during the pre-build stage of my various VS projects.



回答4:

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.



回答5:

I found this for the inno setup section which looks like it would work:

http://agiletracksoftware.com/blog.html?id=4