I wrote an application and its WiX installer and put it under version control using subversion. When the WiX installer builds I want its version number to be the current bui
You could use Product/@Version="!(bind.FileVersion.FileId)"
(replace FileId
with the Id
of the file from which you'd like to get the version number) and light.exe will populate the value with the version of the file referenced by the FileId
.
In case someone is looking for an actual XML example, this works with .NET assemblies (and you don't have to do the Assembly or KeyPath attributes). I eliminated unrelated code with [...] place holders:
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product [...] Version="!(bind.fileVersion.MyDLL)">
[...]
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder" Name="PFiles">
<Directory Id="INSTALLDIR" Name="MyDLLInstallLocation">
<Component Id="MainLib" Guid="[...]">
<File Id="MyDLL" Name="MyDll.dll" Source="MyDll.dll" />
[...]
</Component>
[...]
</Directory>
</Directory>
</Directory>
</Product>
</Wix>
This looks reasonably close to what you are trying to accomplish. See what the equivalent is in cruise control.
http://www.ageektrapped.com/blog/setting-properties-for-wix-in-msbuild/
You can pass the version to the MSBuild script for your setup project the same as you can pass for application's build script.
For example, if your CI system defines variables AppVersion
and BuildNumber
, and passes them to your MSBuild scripts, your wixproj can create a corresponding Version
property which it forwards to Wix like this:
<PropertyGroup>
<Version Condition=" '$(BuildNumber)' == '' ">0.0.1</Version>
<Version Condition=" '$(BuildNumber)' != '' ">$(AppVersion).$(BuildNumber)</Version>
<DefineConstants>Version=$(Version)</DefineConstants>
</PropertyGroup>
The first definition of Version
provides a default for when you're building locally. Whatever it ends up with becomes a Version
variable in Wix. Use it in a wsx file like this:
<Product Version="$(var.Version)" ...>
<Package Description="$(var.ProductName) $(var.Version): $(var.ProductDescription)" ... />
I like to include the version in the description so that it's easy to look up from Window Explorer (as a column in Detail view or on the Properties page) independent of the file name.
Passing the version as a variable gives you more control than reading it from a file. When you read from a file, you get all 4 parts of the programmatic version. However, ProductVersion is only designed to use the first 3 parts.
Here's a very simple way to get your Bootstrapper Bundle Version to match your MyApp AssemblyVersion using a BeforeBuild Target
and DefineConstants
.
Bundle.wxs:
<Bundle Name="$(var.ProductName) Bootstrapper v$(var.BuildVersion)"
Version="$(var.BuildVersion)"
Bootstrapper.wixproj:
<Target Name="BeforeBuild">
<GetAssemblyIdentity AssemblyFiles="..\MyApp\bin\$(Configuration)\MyApp.exe">
<Output TaskParameter="Assemblies" ItemName="AssemblyVersion" />
</GetAssemblyIdentity>
<PropertyGroup>
<DefineConstants>BuildVersion=%(AssemblyVersion.Version)</DefineConstants>
</PropertyGroup>
</Target>
I did this in one of my projects by writing a preprocessor extension to read the file version from my executable. So the WiX file looks something like:
<?define ProductName="$(fileVersion.ProductName($(var.MyApp.TargetPath)))" ?>
<?define CompanyName="$(fileVersion.CompanyName($(var.MyApp.TargetPath)))" ?>
<?define ProductVersion="$(fileVersion.ProductVersion($(var.MyApp.TargetPath)))" ?>
<Product
Id="<product ID>"
Name="$(var.ProductName)"
Version="$(var.ProductVersion)"
Manufacturer="$(var.CompanyName)"
Language="1033"
UpgradeCode="<upgrade code>">
I've posted the code for in on CodePlex: http://wixfileversionext.codeplex.com/