4

Hi I have a C/C++ Header file with my products version info init as follows:

#define nMajorVersion 4
#define nMinorVersion 4
#define nPointVersion 8
#define nBuildVersion 33
#define s_szFileVersion "4.4.8.33"
#define s_szProductVersion "4.4.8.33"

Is there any way I can automatically read from this file to update my version number in my wix 3.6 installer? At the moment I have it hard coded and this is not ideal for when it is released. Thanks

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
Natalie Carr
  • 3,707
  • 3
  • 34
  • 68
  • 1
    how about writing a c/c++ program to rewrite the version numbers in the wxs file? – wimh Sep 10 '12 at 18:30
  • @Wimmel I thought the version was set at build time? Is this incorrect? – Natalie Carr Sep 11 '12 at 08:55
  • yes, so you run a program to update the wxs file just before it is build. In your situation you already have a custom header file, so I don't think anything out of the box will solve your problem. I''ll add an answer which allows me better the explain what I mean. – wimh Sep 11 '12 at 10:53
  • [Related question](https://stackoverflow.com/q/626033/145173) (doesn't assume a generated header file). – Edward Brey Mar 26 '19 at 03:58

1 Answers1

6

What you can do is create a c/c++ program which generates a file Version.wxi which looks like this:

<?xml version="1.0" encoding="utf-8"?>
<Include>
  <?define ProductVersion.Major="4"?>
  <?define ProductVersion.Minor="4"?>
  <?define ProductVersion.Revision="8"?>
  <?define ProductVersion.Build="33"?>
  <?define ProductVersion="4.4.8.33"?>
  ....
</Include>

Then you can include and use those version numbers in the main wxs file:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <?include Version.wxi ?>
  <?define UpgradeCode="GUID"?>
  <Product Id="*" 
        Name="$(var.ProductName) $(var.ProductVersion.Major).$(var.ProductVersion.Minor)" 
        Version="$(var.ProductVersion)" Language="1033" 
        Manufacturer="$(var.Company)" UpgradeCode="$(var.UpgradeCode)">

Generate the Version.wxi just before you compile your wix project. For example modify the .wixproj file to add a target which does that.

wimh
  • 15,072
  • 6
  • 47
  • 98