Loading…

WiX Toolset – Supporting major upgrades with installation directory changes while using Burn

Here is the scaffolding to create a WiX installer that uses a Burn bootstrapper that can support upgrading while allowing the user to change to a new installation directory.

Burn

Create an InstallFolder variable and populate it with what you want to be your default installation directory.

<Variable Name="InstallFolder" Type="string" Value="[ProgramFiles64Folder]Company\Product"/>

Pass your InstallFolder variable to your MSI package.

<Chain>
    <MsiPackage Id="MyInstaller" SourceFile="$(var.Installer.TargetPath)">
        <MsiProperty Name="BOOTSTRAPPERINSTALLFOLDER" Value="[InstallFolder]" />
    </MsiPackage>
</Chain>

Candle

In your MSI package, store the installation directory in the registry so we can check it out during an upgrade.

<Feature Id="ProductFeature" Title="Feature1" Level="1">
    <Component Directory='INSTALLFOLDER'>
        <RegistryValue Root='HKLM' Key='SOFTWARE\[Manufacturer]\[Product]'                   
        Name='InstallDirectory' Value='[INSTALLFOLDER]'
        Type='string' />
    </Component>
</Feature>

During install, retrieve the previous installation directory; if it exists.

<Property Id='PREVIOUSINSTALLFOLDER'>
    <RegistrySearch Id='PreviousInstallLocation' Root='HKLM'
                    Key='SOFTWARE\[Manufacturer]\[Product]'
                    Name='InstallDirectory' Type='raw' />
</Property>

Finally, set the INSTALLFOLDER property to either the previous installation directory or the installation directory supplied by the bootstrapper.

<SetProperty Action="SetINSTALLFOLDER1" Id="INSTALLFOLDER" Value="[PREVIOUSINSTALLFOLDER]" After="AppSearch"><![CDATA[BOOTSTRAPPERINSTALLFOLDER = "C:\Program Files\Company\Product" AND PREVIOUSINSTALLFOLDER <> ""]]></SetProperty> 
<SetProperty Action="SetINSTALLFOLDER2" Id="INSTALLFOLDER" Value="[BOOTSTRAPPERINSTALLFOLDER]" After="AppSearch"><![CDATA[BOOTSTRAPPERINSTALLFOLDER <> "C:\Program Files\Company\Product" OR PREVIOUSINSTALLFOLDER = ""]]></SetProperty> 

The installer will behave as follows:

  • Clean install, no installation directory selected -> Default installation directory
  • Clean install, installation directory selected -> Selected installation directory
  • Upgrade, no installation directory selected -> Previous install directory
  • Upgrade, installation directory selected -> Selected installation directory

What’s also nice about this configuration is that you have access to PREVIOUSINSTALLFOLDER at anytime you could schedule a custom action. This allows you to do any migration to the new folder. This might include moving data files from the previous install folder to the new one.

Leave a Reply