Removing files when uninstalling WiX

Use RemoveFile element with On=”uninstall“. Here’s an example:

<Directory Id="CommonAppDataFolder" Name="CommonAppDataFolder">
  <Directory Id="MyAppFolder" Name="My">
    <Component Id="MyAppFolder" Guid="*">
      <CreateFolder />
      <RemoveFile Id="PurgeAppFolder" Name="*.*" On="uninstall" />
    </Component>
  </Directory>
</Directory>

Update

It didn’t work 100%. It removed the files, however none of the additional directories –
the ones created after the installation – were removed. Any thoughts on that? – pribeiro

Unfortunately Windows Installer doesn’t support deleting directories with subdirectories. In this case you have to resort to custom action. Or, if you know what subfolders are, create a bunch of RemoveFolder and RemoveFile elements.

Leave a Comment