tags:

views:

3088

answers:

3

I have a wix installer and a single custom action (plus undo and rollback) for it which uses a property from the installer. The custom action has to happen after all the files are on the hard disk. It seems that you need 16 entries in the wxs file for this; eight within the root, like so:

<CustomAction Id="SetForRollbackDo" Execute="immediate" Property="RollbackDo" Value="[MYPROP]"/>
<CustomAction Id="RollbackDo" Execute="rollback" BinaryKey="MyDLL" DllEntry="UndoThing" Return="ignore"/>
<CustomAction Id="SetForDo" Execute="immediate" Property="Do" Value="[MYPROP]"/>
<CustomAction Id="Do" Execute="deferred" BinaryKey="MyDLL" DllEntry="DoThing" Return="check"/>
<CustomAction Id="SetForRollbackUndo" Execute="immediate" Property="RollbackUndo" Value="[MYPROP]"/>
<CustomAction Id="RollbackUndo" Execute="rollback" BinaryKey="MyDLL" DllEntry="DoThing" Return="ignore"/>
<CustomAction Id="SetForUndo" Execute="immediate" Property="Undo" Value="[MYPROP]"/>
<CustomAction Id="Undo" Execute="deferred" BinaryKey="MyDLL" DllEntry="UndoThing" Return="check"/>

And eight within the InstallExecuteSequence, like so:

<Custom Action="SetForRollbackDo" After="InstallFiles">REMOVE&lt;>"ALL"</Custom>
<Custom Action="RollbackDo" After="SetForRollbackDo">REMOVE&lt;>"ALL"</Custom>
<Custom Action="SetForDo" After="RollbackDo">REMOVE&lt;>"ALL"</Custom>
<Custom Action="Do" After="SetForDo">REMOVE&lt;>"ALL"</Custom>
<Custom Action="SetForRollbackUndo" After="InstallInitialize">REMOVE="ALL"</Custom>
<Custom Action="RollbackUndo" After="SetForRollbackUndo">REMOVE="ALL"</Custom>
<Custom Action="SetForUndo" After="RollbackUndo">REMOVE="ALL"</Custom>
<Custom Action="Undo" After="SetForUndo">REMOVE="ALL"</Custom>

Is there a better way?

A: 

I've had some experience with Wix, but I'm not an expert. Are you trying to do 8 different things or just one?

Slapout
A single custom action, which has to be undone on uninstall, or if the installation is rolled back.
Khoth
+1  A: 

If you have complex custom actions that need to support rollback, you might consider writing a Wix extension. Extensions typically provide authoring support (i.e. new XML tags that get mapped to MSI table entries), plus automatic scheduling of custom actions.

It's more work than just writing a custom action, but once your CAs reach a certain level of complexity, the ease-of-authoring that extensions provide can be worth it.

Paul Lalonde
+2  A: 

The WiX custom actions are a great model to follow. In this case, you only declare, with CustomAction, the immediate action, the deferred action, and the rollback action. You only schedule, with Custom, the immediate action, where the immediate action is implemented as code in a native DLL.

Then, in the immediate action's code, you call MsiDoAction to schedule the rollback and deferred actions: as they are deferred, they are written into the script at the point you call MsiDoAction rather than executed immediately. You'll need to call MsiSetProperty as well to set the custom action data.

Download the WiX source code and study how the IISExtension works, for example. WiX actions generally parse a custom table and generate the data for the deferred action's property based on that table.

Mike Dimmick