Rob Smyth
Rob Smyth

Reputation: 1858

In Wix how do I format version from X.X.X.X to X.X.X

I have a product where the customers expect a 3 part version number like 1.2.3 but internally we use 1.2.3.4. The version is set automatically in the Wix installer, so how do I drop the last number (4)?.

Context

The last number, in the example '4', is the subversion commit number that is automatically generated. Our customers do not want to see "release 5.6.1.7654" but want to see "release 5.6.1". That is the nature of our market. We do display the full number in the Help | About dialog.

Implementation

In the Wix XML we have:

  <?define ProductVersion="!(bind.FileVersion.MyExe)" ?>
      :
  <Product 
      :
       Version="$(var.ProductVersion)"
      :

How do I format the $(var.ProductVersion) from X.X.X.X to X.X.X?

Thanks in advance

Rob

Upvotes: 2

Views: 2689

Answers (3)

Sunil Agarwal
Sunil Agarwal

Reputation: 4277

Simplest approach will be to have assemblyversionInfo in project and use the version number from this file

enter image description here

Upvotes: 0

Netfangled
Netfangled

Reputation: 2081

You could do all that with the preprocessor instead of the binder. That's how I do it anyway. I wrote a preprocessor extension that takes a version number (string) as parameter and returns a new one. So you could do the same, such as:

switch (function)
{
    case "TruncateVersion":
        // validate version number here
        return args[0].Substring(0, args[0].LastIndexOf('.'));
}

Here's a link on how to extend the preprocessor: http://wix.sourceforge.net/manual-wix3/extension_development_preprocessor.htm

Then, you could get your version number using $(version.TruncateVersion($(var.MyProject.TargetPath))).

Of course, that's only the path. You can extract the file version using the FileVersionInfo class or grab it directly from your AssemblyInfo.cs file.

Or, if you'd rather do the work at bind time, you could write a binder extension. Unfortunately, WiX extensions are poorly documented at the moment and only the preprocessor seems to have a complete, documented example. Although I've seen fragments of Heat extensions here and there.

Feel free to prove me wrong by checking the WiX source code or scouring the net. Good luck!

EDIT

Forgot to mention. You cannot use this syntax: $(version.TruncateVersion(!(bind.fileVersion.FileID)))

This is because the preprocessor variables, starting with '$', are resolved before bind variables are resolved by the binder, which start with '!'.

You can, however, do the opposite: !(bind.fileVersion.$(var.MyProject.TargetPath))

Upvotes: 0

Magnus Johansson
Magnus Johansson

Reputation: 28325

There is a special assembly property meant for this, AssemblyInformationalVersion. It would be the best choice, since it also allows you to specify text, like "Release 5.6.1 RC1". However, I'm not sure the WIX toolset support it yet.

Another thing you can do is to use a global AssemblyInfo.cs technique in your project/solution. Define the AssemblyVersion and AssemblyFileVersion in that file as you want them to be presented to the user and keep using 4 stage incremental build numbers on your other assemblies.

Upvotes: 1

Related Questions