How can I set the WiX installer version to the current build version?

C#SvnWix

C# Problem Overview


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 build version of the application. How do I accomplish this? I used c# to code the application.

N.B. I am using ccnet to build this project

C# Solutions


Solution 1 - C#

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.

Solution 2 - C#

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/

Solution 3 - C#

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>

Solution 4 - C#

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>

Solution 5 - C#

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.

Solution 6 - C#

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/

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDracoView Question on Stackoverflow
Solution 1 - C#Rob MenschingView Answer on Stackoverflow
Solution 2 - C#Chris KaczorView Answer on Stackoverflow
Solution 3 - C#K0D4View Answer on Stackoverflow
Solution 4 - C#Brock HensleyView Answer on Stackoverflow
Solution 5 - C#Edward BreyView Answer on Stackoverflow
Solution 6 - C#JohnWView Answer on Stackoverflow