views:

329

answers:

4

I created a class derived from System.Configuration.Install for my installer.
But the code in Uninstall() is being called when I try to update the application.
How can I detect that the user is trying to update instead of uninstall?

Maybe this post explains it better than me:

My problem boils down to: when the user performs an update (i.e. double clicks on MyAppVer2.msi when they already have MyAppVer1.msi installed) the Uninstall method inside my Installer is called first, but I have no apparent property to check from inside this method to detect that an update is being performed so that I can branch my code appropriately.

A: 

Blind guess here, but I'd start out by checking the Installer.Context property for a parameter. If that's no help, there may be something in the savedState parameter passed to Uninstall.

Last chance would be to prompt the user, and set the child installers as appropiate.

Mark Brackett
Thanks. There is nothing helpful in Installer.Context or savedState.
Douglas Tosi
Then I suspect you'll just need to prompt the user, or shell out for InstallShield proper or something. There's been a lot of complaints of how poor .NET supports MSI, but nobody planning on fixing it AFAIK.
Mark Brackett
A: 

The deployment project that ships with Visual Studio is SEVERELY underpowered to deal with anything beyond the simpiliest scenarios.

In your case, you'll need to do one of the following:

  1. Figure out a way to set a flag prior to the original MSI being uninstalled, which you can check in the installer class.
  2. Prompt the user visually in the installer class.
  3. Redesign your install/uninstall logic to not be dependant on the situation in which the uninstaller was called.
Joseph Daigle
+1  A: 

There is a setting in your setup project that will "uninstall" previous versions by default, turn this flag OFF, then you will not have to worry!

Mitchel Sellers
With that option OFF, when I look at Control Panel -> Add/Remove Programs I see various entries. One for each version I installed.
Douglas Tosi
Yes, that is a downfall of the windows installer.As other posters have mentioned you would want to look at other solutions...I just know that the option is the only valid workaround with the default functionality.
Mitchel Sellers
+1  A: 

Is there a reason why you can't use WIX, which can handle this sort of thing more efficiently, have a look at the Upgrade tutorial, Here

CheGueVerra
Thanks, I'll have a look at it.
Douglas Tosi