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开发者_如何学Go 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?
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.
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.
i think what you need to do is add "Return" item in your customaction, then if the custom action returns value no-zero, your installation will fail and roll back.
what you need to do is to make sure your customaction returns no-zero value when fail.
ExeCommand="[INSTALLLOCATION]BeforeUnstall.bat" Execute="deferred" Return="check" HideTarget="no" Impersonate="no" />
精彩评论