title: WIX Custom Action - run at different times for install, upgrade and uninstall
body: <p>I have a custom action that removes various directories as part of the uninstall process. I want to call this action at different points in the install sequence depending on what's being done:</p>
  
  <ul>
  <li>During an install, don't run the custom action</li>
  <li>During an upgrade, run the custom action after RemoveExistingProducts</li>
  <li>During an uninstall, run the custom action after RemoveFolders</li>
  </ul>
  
  <p>I can likely get each one of these to work individually, but how do I get them to work together how I want. I tried something like this (some code take from <a href="https://stackoverflow.com/questions/320921/how-to-add-a-wix-custom-action-that-happens-only-on-uninstall-via-msi">here</a>):</p>
  
  <pre><code>&lt;InstallExecuteSequence&gt;
  
    &lt;Custom Action="PreventDowngrading" After="FindRelatedProducts"&gt;
      NEWERPRODUCTFOUND AND NOT Installed
    &lt;/Custom&gt;
  
    &lt;LaunchConditions After="AppSearch" /&gt;
    &lt;RemoveExistingProducts Before="InstallInitialize" /&gt;
  
    &lt;!-- NEW _&gt; Clean old files AFTER uninstall during an upgrade --&gt;
    &lt;Custom Action="CleanUp"  After="RemoveExistingProducts" &gt;
      UPGRADINGPRODUCTCODE
    &lt;/Custom&gt;
  
    &lt;!-- NEW _&gt; Clean old files LAST during an uninstall --&gt;
    &lt;Custom Action="CleanUp"  After="RemoveFolders" &gt;
      (NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")
    &lt;/Custom&gt;
  
  &lt;/InstallExecuteSequence&gt;
  </code></pre>
  
  <p>But get a duplicate symbol error when I do a build. Any help will be greatly appreciated!</p>