Draco
Draco

Reputation: 16364

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

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

Upvotes: 150

Views: 87369

Answers (7)

vdschuck
vdschuck

Reputation: 166

In the projects I've been working on, I've used the following approach:

I define the version in the Directory.Build.props file

<?xml version="1.0" encoding="utf-8"?>
<Project>
  <PropertyGroup>
    <LangVersion>latest</LangVersion>
    <Version>0.1.0</Version>
  </PropertyGroup>
</Project>

In .wixproj get the version and define a constant

<Project Sdk="WixToolset.Sdk/4.0.0">
    <PropertyGroup>
        <OutputName>Example_MSI_name_v$(Version)_$(RuntimeIdentifier)</OutputName>
        <DefineConstants>
            ProductVersion=$(Version);
        </DefineConstants>
    </PropertyGroup>
</Project>

and inside the .wxs file, the package settings are defined

<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">

    <Package ProductCode="*"
             UpgradeCode="$(var.UpgradeCode)"
             Name="!(loc.ProductName)"
             Language="!(loc.Language)"
             Version="$(var.ProductVersion)"
             Manufacturer="!(loc.Company)">

        [...]

    </Package>
</Wix>

Upvotes: 3

Rob Mensching
Rob Mensching

Reputation: 35866

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. See the WiX v3 documentation for all the available variables.

Upvotes: 196

Edward Brey
Edward Brey

Reputation: 41648

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.

Upvotes: 11

K0D4
K0D4

Reputation: 2603

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>

Upvotes: 43

Brock Hensley
Brock Hensley

Reputation: 3645

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>

Upvotes: 26

Chris Kaczor
Chris Kaczor

Reputation: 584

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/

Upvotes: 39

JohnW
JohnW

Reputation: 3032

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/

Upvotes: 5

Related Questions