Once you’ve learnt the basics of using WiX to create msi installers, one of the more sophisticated techniques to master is the Remember Property pattern.

With this pattern, you provide commandline properties to your installer for the first installation that are persisted in the registry for later reuse, by an upgrade or a repair.

WiX’s benevolent dictator, Rob Mensching has an excellent post “The WiX toolset’s ‘Remember Property’ pattern” which goes into some detail on how to do this right.

However, that post is a few years old, and requires a minor hack in the form of a CustomAction.

I wondered if there was a better way to solve the problem, with more recent versions of WiX - and I found that there was.

Here’s a working example for a “SERVER” property, though note that I’m not showing all of the installer, just the elements necessary.

First we have a simple declaration to mark our property as secure.

<Property Id="SERVER"
          Secure="yes"/>

In theory we don’t need this, but in practice I found my msi didn’t upgrade property when deployed through SCCM without this. YMMV.

Next we have a second property - in my case distinguished by the “P.” prefix - into which we load any value previously stored in the registry.

<Property Id="P.SERVER">
  <RegistrySearch Id="S.SERVER"
                  Root="HKLM"
                  Key="SOFTWARE\Niche Software\[ProductName]"
                  Name="Server"
                  Type="raw"
                  Win64="$(var.Win64)"/>
</Property>

If we didn’t get a value for SERVER passed on the commandline, we want to overwrite it with the value loaded from the registry, if any.

<SetProperty Id="SERVER"
             Value="[P.SERVER]"
             After="AppSearch">NOT(SERVER)</SetProperty>

Finally, we store the value we used in the registry, so that we can reload it next time our installer is activated:

<RegistryValue Root="HKLM"
               Key="SOFTWARE\Niche Software\[ProductName]"
               Name="Server"
               Value="[SERVER]"
               Type="string"/>

This last element needs to be part of a component that gets installed, preferably one that’s conditional on SERVER being defined. All the other elements can nest directly under your master <Product> element.

Even though I’ve used this to good effect in several installers so far, there are sure to be ways this can be improved.

Comments

blog comments powered by Disqus
Next Post
Blink Estimation  11 Aug 2013
Prior Post
Why attend a user group meeting?  12 May 2013
Related Posts
Checklists, Automation and Consistency  19 Jul 2015
Deploying with a bin folder  05 Nov 2013
WiX Techniques Updated  30 Oct 2008
WiX Techniques  12 Sep 2008
NAnt and WiX Versioning  27 Aug 2008
Archives
August 2013
2013