Best Practices: WiX - Removing Files on Uninstall (RemoveFile)
Is there anything worse than an application that doesn't fully and completely uninstall? OK, there's those folks who insist on tab-aligning variable initializations but we won't go there again...
Really though, if you're using WiX and you want your app to completely uninstall one of the things that you might want to do is to remove the app completely from the file system. The problem is that, by default, the Windows Installer only removes files that the install package put on the hard disk. But what if your app creates new files and you want the uninstall to remove these?
The secret lies within the trusty RemoveFile node. This baby exists just for this purpose. So a snippet like this, will remove a file that wasn't copied by the installer to the file system on the install:
<
RemoveFile Id="64B59C2F-27A0-4c9c-8349-DE555FC50ED5" Name="MyAppsFile.txt" On="uninstall" />A couple of other notes on the RemoveFile node. If you don't specify a Name, RemoveFile will remove the ParentDirectory folder - however, it won't remove the folder unless the folder is empty.
Also keep in mind that the Name attribute supports wildcards. So, something like this:
<RemoveFile Id="64B59C2F-27A0-4c9c-8349-DE555FC50ED5" Name="*.txt" On="uninstall" />
<RemoveFile Id="76B8C0C3-7743-4ef0-820D-EC99B02920DC" On="uninstall" />
Will ensure that all txt files will be removed and then the directory will be removed on an uninstall.
These techniques should help you keep the uninstall pretty tidy. Happy WiXing!