Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force WiX to uninstall if there is an error in CustomAction

I have following CustomAction:

<CustomAction Id="ActionName"
              After="InstallFinalize">
  <![CDATA[NOT Installed AND (VSTORUNTIME4="#1")]]>
</CustomAction>

The problem is that there is a case in CustomAction when I return ActionResult.Failure. In this case installer will show error message and say that installation failed, but application is still partially installed (files are already in Program Files and application shows up in Uninstall programs).

I want that if I return ActionResult.Failure then installation will be aborted and uninstalled. This is what happens if custom action fails in default Visual Studio installer and I think it makes more sense.

Does anybody know how to trigger uninstall if Custom Action failed? Do I need to add something extra to WiX XML?

like image 301
victor Avatar asked Feb 11 '11 22:02

victor


2 Answers

Currently your custom action is scheduled after the installation transaction was completed (After="InstallFinalize"). The only custom actions that can be rolled back are "deferred" custom actions that are scheduled between "InstallInitialize" and "InstallFinalize". For your deferred custom actions you should also schedule a rollback custom action before it.

like image 55
Rob Mensching Avatar answered Sep 22 '22 13:09

Rob Mensching


Windows Installer supports a transactional story by default with the ability to rollback all changes to the system. The question is, what are you custom actions doing and where/how are they scheduled?

If your CustomActions are changing the state of the machine they need to do so in a transactional manner otherwise the installer can't rollback the out of process changes your code caused.

Here's a couple good reading articles:

Installation Phases and In-Script Execution Options for Custom Actions in Windows Installer

Zataoca: Classes of Custom Actions

Zataoca: Custom actions should be data driven.

Zataoca: Custom actions are (generally) an admission of failure.

like image 31
Christopher Painter Avatar answered Sep 20 '22 13:09

Christopher Painter