views:

330

answers:

2

I have a .NET deployment project. I would like to add a custom uninstall action that checks certain conditions and optionally cancels the uninstallation. Is that possible?

As far as I figured out, it's only possible to define custom actions that cannot influence the main installer itself.

A: 

It would surprise me if it's possible. In my experience, as soon as you try to use the VS install project to do anything that can't be drag'ndropped in the designer, you're asking for trouble.

In other words, it sucks, but I don't know whether the grass is greener on the other side (e.g. InstallShield), because I've never used that.

erikkallen
+1  A: 

The answer is actually quite easy but also quite ugly.

At the point in the custom action where I want to cancel the uninstallation I just throw an ApplicationException:

//Nono. Don't uninstall. To abort uninstall, throw an exception
throw new ApplicationException(Constants.CONST_APP_NAME + @" can't be uninstalled because the preparation hasn't been completed.");
Tobias