Search code examples
.netwixwindows-installercustom-actionisolatedstorage

How do I remove my application's Isolated Storage files and data from within a MSI custom action?


I have a .NET 4.0 application that uses Isolated Storage to store user files for my application. This ends up using a folder structure like the following:

%LocalAppData%\IsolatedStorage\af34odgf.fj1\bheukjsx.mvr\Url.vc242bhqlc4nzx5043sp5wof15zyzvq0\AssemFiles.

This is fine, I think. However, since these directories and files are created after my application is installed, Windows Installer will not remove them. There are many references online that indicate that one should use a custom action to remove files and directories that are created after installation. I am stuck on how to actually implement this for IsolatedStorage. Specifically, how do I obtain the path to the Isolated Storage folder of my application from the context of the custom action?

If I execute something like IsolatedStorageFile.GetUserStoreForApplication(); from my custom action, won't "application" refer to my installer rather than my application? If so, that would give me a completely different and new Isolated Storage folder path. Or do I have a misconception about where the custom action DLLs "live"?

I am currently using WiX, but I suspect the answer is likely independent of that.


Solution

  • I think the best way to address this is to have the application save just the Isolated Storage path in the registry, rather than attempting to maintain a path list of every file that the Isolated Storage code for the application ever creates or deletes.

    When uninstalling, this registry entry can be read and used with a WiX utils extension called RemoveFolderEx. This extension differs from RemoveFolder in that RemoveFolderEx will remove a folder and its contents.

    Also, see this related question/answer, IsolatedStorage: Delete preferences in uninstaller?, which suggests that one might be able to move the Isolated Storage code into a separate assembly that is shared between the main application and the installer, allowing them to reference the same Isolated Storage stores.