Neil
Neil

Reputation: 5239

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?

Upvotes: 4

Views: 1892

Answers (3)

zett42
zett42

Reputation: 27766

WiX v4 adds the Condition attribute to RemoveFolderEx:

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

The component condition should be removed as it only controls whether the component that contains the RemoveFolderEx, will be installed.

Upvotes: 0

Ciprian
Ciprian

Reputation: 3565

The component condition controls whether a component is installed. This condition is false on install thus the component is not installed. Naturally on uninstall it doesn't get removed, thus the remove operation doesn't work. I would go with a custom action that sets the target property conditionally.

Upvotes: 0

Bob Arnson
Bob Arnson

Reputation: 21886

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.

Upvotes: 5

Related Questions