Search code examples
wixwindows-installer

Wix: Can I impose a condition on a RemoveFolderEx element to only run when the program is being uninstalled?


I am trying to delete a folder hierarchy using the RemoveFolderEx but only when I'm uninstalling the software. Currently when I do a reinstall it deletes all the folders as well which deletes all the program created content which is undesirable. This is probably because I've set the software to be uninstalled before being reinstalled

<InstallExecuteSequence>
    <RemoveExistingProducts Before="InstallInitialize" />      
</InstallExecuteSequence>

Is it possible to impose a condition on the following element? Should I wrap it in it's own component then add a condition inside? I've not been able to get it to work thus far.

<util:RemoveFolderEx On="uninstall" Property="MAINDIR" ></util:RemoveFolderEx>

From another question I know the condition has to be

((NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL"))

but i'm not quite 100% on how to apply this to the removefolder element if it's even possible.

I guess I could set the path of the folder to empty on a custom action which was subject to the condition but this just seems hacky.

Cheers. Neil


EDIT: I've almost got this working by putting the removefolderex into its own component. Without the condition it works as expected and removes the data directory on uninstall and a reinstall. When I add the condition in it doesn't run but I'm hoping that this is down to the condition being wrong.

<DirectoryRef Id="DATADIR">        
    <Component Id="C.RemoveDataFolder" Guid="myguid" KeyPath="yes">
        <util:RemoveFolderEx On="uninstall" Property="DATADIR" ></util:RemoveFolderEx>
        <Condition>(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")</Condition>
    </Component>
</DirectoryRef>

Does anyone know if the above declaration ok or will this never work? Can I apply this kind of condition to a component?


Solution

  • RemoveFolderEx is tied to a component, so if it's being removed and RemoveFolderEx/@On="uninstall" then RemoveFolderEx will do its thing. There's no support for adding another condition, but that seems reasonable; please file a feature request so it's on the todo list.