Introduction
A typical Major Upgrade removes a previous version of an application and installs a new version. This blog will guide you through the process of creating Major Upgrade.
Source code for RTM version
Let's create a C# solution with two projects in it: library and console application. Here is the code for the library:
using System;
using System.Collections.Generic;
using System.Text;
namespace TestLib
{
public class TestClass
private string greeting;
public TestClass()
greeting = "Hello, World!";
}
public TestClass(string greeting)
this.greeting = greeting;
public void WriteLine()
Console.WriteLine(greeting);
Here is the code for the console application:
using TestLib;
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
namespace
class Program
static void Main(string[] args)
TestClass test = new TestClass();
test.WriteLine();
As you can see, console application is using default constructor, so calling WriteLine method of the TestClass class will print out "Hello, World!" message.
Source code for V2 version
For version 2 of our product we will change the console application to use a non-default constructor to pass the greeting string the the TestClass instance:
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]
TestClass test = new TestClass("QFE version");
Our updated version of application will print out "QFE version" message instead of default "Hello, World!". Notice also that AssemblyVersion and AssemblyFileversion have changed.
Installation Wix script with no Major Upgrade support
Typical installation script for such program would be something like this:
<?xml version='1.0' encoding='windows-1252'?>
<Wix xmlns='http://schemas.microsoft.com/wix/2003/01/wi'>
<?define SkuName = "TestApp"?>
<?define ProductVersion="1.0.0" ?>
<?define UpgradeCode="{3485E6A2-A1F3-4329-8BB5-ED8FFCF283D4}"?>
<?define Manufacturer="Acme Corp."?>
<?define ProductCode="{5C32A3BD-3BA3-43AF-951F-1077E84B00DC}"?>
<?define PackageCode="{????????-????-????-????-????????????}"?>
<Product Id='$(var.ProductCode)'
Name='ProductName'
Language='1033'
Version='$(var.ProductVersion)'
Codepage='1252'
Manufacturer='$(var.Manufacturer)'
UpgradeCode='$(var.UpgradeCode)'>
<Package Id='$(var.PackageCode)'
Description="PackageDescription"
Comments='Comments'
InstallerVersion='200'
Languages='1033'
SummaryCodepage='1252'
Compressed='yes'
AdminImage='no'
Platforms='Intel'
ReadOnly='yes'
ShortNames='no'
Keywords='Installer,MSI,Database' />
<Media Id="1" Cabinet="$(var.SkuName).cab" EmbedCab="yes" />
<Directory Id='TARGETDIR' Name='SourceDir'>
<Directory Id='LocalAppDataFolder'>
<Directory Id='INSTALLDIR' Name='TestApp'>
<Component Id='$(var.SkuName)' Guid='{835A4136-B01E-4F8B-8EA7-5D6F69B07A83}'>
<File Id='TestAppExe' DiskId='1' KeyPath='yes' Checksum='yes'
Vital='yes' Name='TestApp.exe' Assembly='.net'
AssemblyManifest='TestAppExe'
AssemblyApplication='TestAppExe'
Source='TestApp.exe' />
</Component>
<Component Id='TestLibDll_Component' Guid='{5BC55186-170E-475C-B77A-D80581FC88EC}'>
<File Id='TestLibDll' Name='TestLib.dll' DiskId='1' KeyPath='yes'
Vital='yes' Assembly='.net' AssemblyManifest='TestLibDll'
AssemblyApplication='TestLibDll' Source='TestLib.dll' />
</Directory>
<Feature Id='Complete' Level='1'>
<ComponentRef Id='$(var.SkuName)' />
<ComponentRef Id='TestLibDll_Component' />
</Feature>
</Product>
</Wix>
Aside from UpgradeCode that script does not have any support for major upgrades.
Preparing an application for future major upgrades
Here is what needs to be done from purely MSI standpoint in order to support major upgrades:
Here is how these items translates to Wix:
<Upgrade Id="$(var.UpgradeCode)"> <UpgradeVersion Minimum="$(var.ProductVersion)" IncludeMinimum="no" OnlyDetect="yes" Language="1033" Property="NEWPRODUCTFOUND" /> <UpgradeVersion Minimum="$(var.RTMProductVersion)" IncludeMinimum="yes" Maximum="$(var.ProductVersion)" IncludeMaximum="no" Language="1033" Property="UPGRADEFOUND" /> </Upgrade>
<Upgrade Id="$(var.UpgradeCode)">
<UpgradeVersion Minimum="$(var.ProductVersion)"
IncludeMinimum="no"
OnlyDetect="yes"
Language="1033"
<UpgradeVersion Minimum="$(var.RTMProductVersion)"
IncludeMinimum="yes"
Maximum="$(var.ProductVersion)"
IncludeMaximum="no"
</Upgrade>
Id attribute of the <Upgrade> element is set to a value of UpgradeCode property (UpgradeCode attribute of <Product> element) and will be added to the UpgradeCode column of every record in the Upgrade table. Every <UpgradeVersion> element adds a new record to the Upgrade table. Minimum attribute of the <UpgradeVersion> element sets the value of VersionMin column. Maximum attribute of the <UpgradeVersion> element sets the value of VersionMax column. Property attribute of the <UpgradeVersion> element sets the value of ActionProperty column. Here is the relationships between flag bits in Attributes column of the Upgrade table and attributes of the <UpgradeVersion> element: Flag Attribute Description msidbUpgradeAttributesMigrateFeatures MigrateFeatures Enables the logic of MigrateFeatureStates action of migrating feature states. msidbUpgradeAttributesOnlyDetect OnlyDetect Detects products and applications but does not remove. msidbUpgradeAttributesIgnoreRemoveFailure IgnoreremoveFailure Continues installation upon failure to remove a product or application. msidbUpgradeAttributesVersionMinInclusive IncludeMinimum Detects the range of versions including the value in VersionMin. msidbUpgradeAttributesVersionMaxInclusive IncludeMaximum Detects the range of versions including the value in VersionMax. msidbUpgradeAttributesLanguagesExclusive ExcludeLanguages Detects all languages, excluding the languages listed in the Language column.
Id attribute of the <Upgrade> element is set to a value of UpgradeCode property (UpgradeCode attribute of <Product> element) and will be added to the UpgradeCode column of every record in the Upgrade table.
Every <UpgradeVersion> element adds a new record to the Upgrade table.
Minimum attribute of the <UpgradeVersion> element sets the value of VersionMin column.
Maximum attribute of the <UpgradeVersion> element sets the value of VersionMax column.
Property attribute of the <UpgradeVersion> element sets the value of ActionProperty column.
Here is the relationships between flag bits in Attributes column of the Upgrade table and attributes of the <UpgradeVersion> element:
<!-- Prevent downgrading --> <CustomAction Id="PreventDowngrading" Error="Newer version already installed." />
<!-- Prevent downgrading -->
<CustomAction Id="PreventDowngrading"
Error="Newer version already installed." />
<InstallExecuteSequence> <Custom Action="PreventDowngrading" After="FindRelatedProducts">NEWPRODUCTFOUND</Custom> <RemoveExistingProducts After="InstallFinalize" /> </InstallExecuteSequence> <InstallUISequence> <Custom Action="PreventDowngrading" After="FindRelatedProducts">NEWPRODUCTFOUND</Custom> </InstallUISequence>
<InstallExecuteSequence>
<Custom Action="PreventDowngrading"
After="FindRelatedProducts">NEWPRODUCTFOUND</Custom>
<RemoveExistingProducts After="InstallFinalize" />
</InstallExecuteSequence>
<InstallUISequence>
</InstallUISequence>
Here is an updated installation script:
<?
<Product Id='{8EEB7D19-F7F4-4218-93B9-BBEAAA4C2E2D}'
<CustomAction Id="PreventDowngrading" Error="Newer version already installed." />
<!-- Sequences -->
<Custom Action="PreventDowngrading" After="FindRelatedProducts">NEWPRODUCTFOUND</Custom>
How upgrade works
For FindRelatedProducts to work correctly, the package author must be sure that the ProductLanguage property in the Property table is set to a language that is also listed in the Template Summary Property. FindRelatedProducts should be authored into the InstallUISequence table and InstallExecuteSequence tables. The FindRelatedProducts action must come before the MigrateFeatureStates action and the RemoveExistingProducts action.
For FindRelatedProducts to work correctly, the package author must be sure that the ProductLanguage property in the Property table is set to a language that is also listed in the Template Summary Property.
FindRelatedProducts should be authored into the InstallUISequence table and InstallExecuteSequence tables. The FindRelatedProducts action must come before the MigrateFeatureStates action and the RemoveExistingProducts action.
MigrateFeatureStates action runs through each record of the Upgrade table in sequence and compares the upgrade code, product version, and language in each row to all products installed on the system. If MigrateFeatureStates action detects a correspondence, and if the msidbUpgradeAttributesMigrateFeatures bit flag is set in the Attributes column of the Upgrade table, the installer queries the existing feature states for the product and sets these states for the same features in the new application. The action only migrates the feature states if the Preselected property is not set. The MigrateFeatureStates action should come immediately after the CostFinalize action. MigrateFeatureStates must be sequenced in both the InstallUISequence table and the InstallExecuteSequence table.
MigrateFeatureStates action runs through each record of the Upgrade table in sequence and compares the upgrade code, product version, and language in each row to all products installed on the system. If MigrateFeatureStates action detects a correspondence, and if the msidbUpgradeAttributesMigrateFeatures bit flag is set in the Attributes column of the Upgrade table, the installer queries the existing feature states for the product and sets these states for the same features in the new application. The action only migrates the feature states if the Preselected property is not set.
The MigrateFeatureStates action should come immediately after the CostFinalize action. MigrateFeatureStates must be sequenced in both the InstallUISequence table and the InstallExecuteSequence table.
The RemoveExistingProducts action must be scheduled in the action sequence in one of the following locations.
Windows Installer sets the UPGRADINGPRODUCTCODE Property when it runs this action.