title: Wix: condition on property not working
body: <p>I have a util:RemoveFolderEx element that I only want to run when the program is being uninstalled.  I put it inside its own component then set up a condition on a property as to whether it should be included.</p>
  
  <p>Can anyone explain to me why the following doesn't work?</p>
  
  <pre><code>&lt;Property Id='UNINSTALLMODE' Value="FALSE"&gt;&lt;/Property&gt;
  
  &lt;DirectoryRef Id="DATADIR"&gt;        
      &lt;Component Id="C.RemoveDataFolder" Guid="myguid" KeyPath="yes"&gt;
          &lt;util:RemoveFolderEx On="uninstall" Property="DATADIR" &gt;&lt;/util:RemoveFolderEx&gt;
          &lt;Condition&gt;(UNINSTALLMODE="TRUE")&lt;/Condition&gt;
      &lt;/Component&gt;
  &lt;/DirectoryRef&gt;
  
  &lt;CustomAction Id="CA.SetUninstallMode" Property="UNINSTALLMODE" Value="TRUE" /&gt;
  
  &lt;InstallExecuteSequence&gt;
      &lt;Custom Action="CA.SetUninstallMode" Before="WixRemoveFoldersEx" &gt;(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")&lt;/Custom&gt;
  &lt;/InstallExecuteSequence&gt;            
  </code></pre>
  
  <p>I've checked the logs and the custom action correctly sets UNINSTALLMODE to "TRUE" when uninstalling the software.  On install and reinstall it is "FALSE".  I've tried the custom action to be scheduled Before="WixRemoveFoldersEx" and Before="CostInitialise" which are relevant to the RemoveFoldersEx.</p>
  
  <p>Any help is much appreciated, this is driving me nuts!  Neil</p>
  
  <hr>
  
  <p>EDIT: I updated the wix to this</p>
  
  <pre><code>&lt;Property Id='P.INSTALLMODE' Value='0'&gt;&lt;/Property&gt;
  &lt;Property Id='P.UNINSTALLMODE' Value='0'&gt;&lt;/Property&gt;
  
  &lt;DirectoryRef Id="DATADIR"&gt;        
      &lt;Component Id="C.RemoveDataFolder" Guid="myguid" KeyPath="yes"&gt;
          &lt;util:RemoveFolderEx On="uninstall" Property="DATADIR" &gt;&lt;/util:RemoveFolderEx&gt;
          &lt;Condition&gt;(P.INSTALLMODE = 1) OR (P.UNINSTALLMODE = 1)&lt;/Condition&gt;
      &lt;/Component&gt;
  &lt;/DirectoryRef&gt;
  
  &lt;CustomAction Id="CA.SetInstallModeToTrue" Property="P.INSTALLMODE" Value='1' /&gt;
  &lt;CustomAction Id="CA.SetUninstallModeToTrue" Property="P.UNINSTALLMODE" Value='1' /&gt;
  
  &lt;InstallExecuteSequence&gt;
      &lt;RemoveExistingProducts Before="InstallInitialize" /&gt;            
  
      &lt;Custom Action="CA.SetInstallModeToTrue" Before="ValidateProductID" &gt;(NOT UPGRADINGPRODUCTCODE) AND (NOT PREVIOUSVERSIONSINSTALLED)&lt;/Custom&gt;
      &lt;Custom Action="CA.SetUninstallModeToTrue" Before="ValidateProductID" &gt;(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")&lt;/Custom&gt;
  &lt;/InstallExecuteSequence&gt;
  </code></pre>
  
  <p>The custom actions run immediately after the DATADIR value is read from the registry and before the CostInitialize.  </p>
  
  <p>Here is what happens in the following situations</p>
  
  <ul>
  <li>Install -> condition is met and the component is installed</li>
  <li>Reinstall -> condition is not met but the component is still uninstalled then reinstalled</li>
  <li>Uninstall -> condition is met and the component is uninstalled</li>
  </ul>
  
  <p>All I can take from this is that the condition is only applicable for the installation procedure and once a component is installed it is not possible to impose a condition on it for being removed.</p>
  
  <hr>
  
  <p>EDIT2: Finally got this working by using a property for the removefolderex which is set by a custom action.  Seems simple now.</p>
  
  <pre><code>&lt;Property Id='P.REMOVEDATAFOLDER' Secure='yes' /&gt;
  
  &lt;DirectoryRef Id="DATADIR"&gt;        
      &lt;Component Id="C.RemoveDataFolder" Guid="myguid" KeyPath="yes"&gt;
          &lt;util:RemoveFolderEx On="uninstall" Property="P.REMOVEDATAFOLDER" /&gt;
      &lt;/Component&gt;
  &lt;/DirectoryRef&gt;
  
  &lt;CustomAction Id="CA.SetDataFolder" Property="P.REMOVEDATAFOLDER" Value='[DATADIR]' /&gt;
  
  &lt;InstallExecuteSequence&gt;           
      &lt;Custom Action="CA.SetDataFolder" Before="ValidateProductID" &gt;(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")&lt;/Custom&gt;
  &lt;/InstallExecuteSequence&gt;  
  </code></pre>