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.
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.
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.
Finally, we store the value we used in the registry, so that we can reload it next time our installer is activated:
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