toadflakz
toadflakz

Reputation: 7944

Product Version in WiX 3.5 and Visual Studio WiX Projects

In another question about setting the Product Version attribute for a WiX installer (How can I set the WiX installer version to the current build version?), the most voted answer (which I've tried and works) recommends:

"You could use Product/@Version="!(bind.FileVersion.<FileId>)" and light.exe will populate the value with the version of the file referenced by the FileId."

...which is great, but appears slightly brittle in Visual Studio WiX projects when using the harvesting capabilities of the WiX VS project in that the FileId for an executable might change.

Is there a safer way of referencing a specific file from the auto-generated .wxs files in Visual Studio other than using the FileVersion Preprocessor Extension (http://wixfileversionext.codeplex.com/)?

Upvotes: 1

Views: 1441

Answers (2)

Dave Andersen
Dave Andersen

Reputation: 5447

We use our build system to control all the versioning, and pass it into the WiX project as a msbuild property.

<PropertyGroup>
    <version_major Condition=" '$(version_major)' == '' ">0</version_major>
    <version_minor Condition=" '$(version_minor)' == '' ">0</version_minor>
    <build_number Condition=" '$(build_number)' == '' ">0</build_number>
    <build_vcs_number Condition=" '$(build_vcs_number)' == '' ">0</build_vcs_number>
    <InstallerVersion>$(version_major).$(version_minor).$(build_number).0</InstallerVersion>
</PropertyGroup>

and reference that in the WiX source with Product/@Version="$(var.InstallerVersion)". That would work if your build system also controls the versioning of your binaries.

Upvotes: 1

Yan Sklyarenko
Yan Sklyarenko

Reputation: 32240

You can run the generated .wxs file through the XSL transform (the -t option of heat.exe), which will replace the auto-generated file ID with the one you choose. As a result, you'll be able to safely reference it from elsewhere.

Upvotes: 2

Related Questions