8

I have a WiX installer that has per-feature custom actions that need to be executed on uninstall. Right now I'm running into a problem where the actions execute whether or not the feature was actually installed by the user. The custom actions fail because they expect certain resources to exist and then the entire install is stuck in a broken state.

What is the correct way to run a custom action if and only if its related feature is being uninstalled? I have included the snippet that I'm currently using below, if it helps.

<Custom Action="LaunchUninstallCustomAction" Before="RemoveFiles"><![CDATA[(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL") AND (&FeatureName<=2)]]></Custom>
dskiles
  • 851
  • 1
  • 13
  • 24

2 Answers2

18

Try

<Custom Action="LaunchUninstallCustomAction" Before="RemoveFiles">
   <![CDATA[(NOT UPGRADINGPRODUCTCODE) 
             AND (&FeatureName=2) AND (!FeatureName=3)]]>
</Custom>

See MSDN for details of condition syntax and examples

Samuel Jack
  • 32,712
  • 16
  • 118
  • 155
  • 1
    hi Samuel can you please elaborate the purpose of ![CDATA[(NOT UPGRADINGPRODUCTCODE) in your snippet – Syed Ali May 16 '12 at 09:23
  • IIRC, I included because it was in the original snippet in the question. The purpose is to ensure the custom action is only run when a specific feature is being removed, and not when the whole product is being upgraded. – Samuel Jack May 16 '12 at 10:16
-3

It sounds like the custom actions are broken and not handling missing resources correctly.

How would the CA's handle it if a user manually removes files? What happens if a user deletes the application folder, and then tries to remove it via ARP?

What happens if a user just removes a feature, without uninstalling the entire application? You'll be better off long-term fixing the CA's.

saschabeaumont
  • 22,080
  • 4
  • 63
  • 85
  • That doesn't answer my question. I know that it's not the best way to do it, but I'm constrained by legacy code that I can't avoid. Given that it isn't the best way to do it, what is the best way to do it, given the constraints provided? – dskiles Feb 03 '10 at 15:14
  • There can be a situation when a custom step cannot detect whether it had to be run or not based on the environment. – Dennis Jan 14 '13 at 14:51