3

I'm trying to bind the file version from my exe file to be used as product version. Following: How can I set the WiX installer version to the current build version?

The problem is that my assembly builds in the format of e.g 2018.0.0.0. The major upgrade requires a version number of max 255, which means that I have to remove the first two numbers from my productVersion variable before setting it to the ProductVersion property. Is there a way to modify the variable through xsl or something else?.

Modifying through a custom action is no alternative since I want the property to be set in the msi file.

Any help in this djungle is appreciated,

 <?define productVersion= !(bind.FileVersion.MyExe.Exe) ?>

 <Product Id="*" 
       UpgradeCode="12345678-1234-1234-1234-123456789123" 
       Name="My Application" 
       Language ="1033" 
       Version="$(var.productVersion)"
       Manufacturer="My Company" >
Sebastian
  • 219
  • 2
  • 13
  • Can you change your EXE versioning to match symantic versioning standards? – Christopher Painter Apr 26 '18 at 16:05
  • In this case I want to keep it outside the symantic versioning standards because of certain conditions. – Sebastian Apr 27 '18 at 06:35
  • Is 2018.0.0.0 your assembly version or your assembly file version? – Christopher Painter Apr 27 '18 at 10:50
  • Both the assembly version and the assembly file version is set to this. It would maybe be possible to do this through a powershell script, but I don't want to overload the cake script with unecessary "hacks". I've been looking for a way to get a substring from !(bind.FileVersion.MyExe.Exe) through preprocessor operators. But it doesnt seem to support that. – Sebastian Apr 27 '18 at 11:11
  • FYI- AssemblyVersion is for strong name / gac purposes and AssemblyFileVersion is equiv to win32 FileVersion and is for tracking purposes. It's very common to only change AssemblyVersion on major changes and AssemblyFileVersion on every build. This is how .net base class libraries are hotfixed for example. Perhaps if you do this you could bind to the latter. (See answer below) – Christopher Painter Apr 27 '18 at 11:41
  • Yes, but at the moment I want to keep the major version as a four digit number in the AssemblyVersion of the application and also on the build server. It's only in the ProductVersion property it should be cut by two digits. Even if this sounds like an alien solution, is there no way to manipulate the variable in the way of shortening it by two digits? e.g from 2018.0.0.0 to 18.0.0.0. – Sebastian Apr 27 '18 at 12:09
  • From what I can tell you could create an extension with a custom binder class. I've never had a need / bothered to learn how to do this. I use votive/msbuild so I could always use msbuild property functions (a way to assign msbuild properties with the output of static method calls) and I could imagine a way to get the file version and chop off two digits without ever needing to go through the work of writing a custom extension. – Christopher Painter Apr 27 '18 at 12:19
  • Maybe it's time to make the application match the symantic versioning standards once and for all. Thank you very much for the clarification on this :). – Sebastian Apr 27 '18 at 13:05
  • FWIW, I spelled it wrong earlier. Semantic versioning is what to google for. https://semver.org/ – Christopher Painter Apr 27 '18 at 13:18

1 Answers1

4

If you can't bind/infer from your assembly then you will need to have your build automation pass a wix variable into candle.exe and use that instead of your bind statement.

In a managed code / vsts / tfs environment my typical flow is that the build definition is the source of truth and it increments and sets a buildnumber during the build. A powershell script updates all the AssemblyFileVersion attributes across my AssemblyInfo files based on this and my wixproj (votive/msbuild) does a regex match on this variable to pass it through to candle.

Christopher Painter
  • 54,556
  • 6
  • 63
  • 100