visual-studiovisual-studio-2017windows-installercustom-actionvisual-studio-setup-proje

Custom Action - Only uninstall if installed


I have a Windows Installer project attached to my solution, which allows the user to optionally install two components of the application (they are Windows Services) using a "Checkboxes" dialogue box which I've added to the User Interface, and then Conditions on the Custom Actions...

i.e. in Custom Actions / Install I have

Primary output from ProjectA (Active)
- Condition = PROJECTACHOSEN (i.e. the Checkbox1Property value)

Primary output from ProjectB (Active)
- Condition = PROJECTBCHOSEN (i.e. the Checkbox2Property value)

In Custom Actions / Uninstall, I've added the same two "Primary Outputs".

The problem is, if during installation the user only chose one of the two projects then the uninstaller still tries to uninstall both of services, and of course throws an error when it doesn't find the missing one, causing the uninstall to fail.

What condition can I add in Uninstall to only install the service if it's currently installed?

I've tried:


Solution

  • you can use ?ComponentName to check install state of a component, i used it similarly few months ago.

    Ive found about it in cheat sheet from flexera here