Mark Raymond
Mark Raymond

Reputation: 967

How do you conditionally remove files during uninstall?

I have this WiX fragment:

<Component Id="AppData" Guid="{30967EFB-4B86-4EBB-8486-5271D051082E}">
    <Condition>NOT KEEPAPPDATA</Condition>
    <RemoveFile Id="PurgeAppData" Name="*.*" On="uninstall" />
    <RemoveFolder Id="RemoveAppDataFolder" On="uninstall" />
</Component>

in the appropriate <Directory> element for the directory under application data that the program stores data. However both

msiexec /xpath-to-msi.msi KEEPAPPDATA="TRUE"

and

msiexec /xpath-to-msi.msi

remove the folder, so the condition is not working. I have also tried this condition:

<Condition>KEEPAPPDATA == ""</Condition>

with the same results.

What is the correct way of passing a parameter to msiexec to change behaviour during uninstall? It seems that parameters are just getting ignored.

Upvotes: 2

Views: 2204

Answers (1)

Somedust
Somedust

Reputation: 1170

By default component conditions are not evaluated during uninstall. Here is a similar Stackoverflow question with an answer from Rob Mensching. He suggests using Transitive attribute. From documentation:

If this attribute is set to 'yes', the installer reevaluates the value of the statement in the Condition upon a reinstall. If the value was previously False and has changed to True, the installer installs the component. If the value was previously True and has changed to False, the installer removes the component even if the component has other products as clients.

Upvotes: 1

Related Questions