views:

81

answers:

6

Hi,

So, I have this application for which we are producing further development versions.

If the application gets uninstalled by the user (from Add/Remove Programs let's say), then I want the application to delete a certain folder in the file system which contains app-related information.

However, if the application is upgraded (by downloading a newer installer for this app and installing it), then I want it to keep that folder.

I am under the impression (at the moment) that it is not possible to differentiate between uninstalling/installing and just updating an application from one version to another, because the .NET deployment projects treat upgrading as just another uninstall/install procedure, but this should be possible somehow.

Thanks for taking the time and whatever answers I may get.

A: 

Have you tried using the ClickOnce deployment? It handles all the install and upgrading of the application. By changing the publish status of the files included in the update you can control if the file gets overwritten with an update or stays the same. When the application is uninstalled all the files will be removed.

Brian
+1  A: 

This is not a direct answer, but have you considered using third-party installation software? We use InnoSetup for distributing a .Net application, and we find it fairly easy to use and very flexible. It could certainly handle what you are describing.

Oliver Bock
This is so not what was asked but, IMHO, very definitely a good answer, having just had to go through yet another MSI installer update (and subsequent server reboot!) for some silly software install. I am so glad that we use InnoSetup to deploy (and upgrade) our own software.
shunty
A: 

Using a wix installer will allow you to make this differentiation. This is a more hands on approach, but it will work.

Derek
A: 

You could also try adding some custom preinstall action, which copies the mentioned folder to some temporary folder and then a post install action copies it back to its place. But please, first consider the above sugestions, such as using a more powerfull installer, or clickOnce.

Hassan
+1  A: 

The installer has three GUID codes, ProductCode, PackageCode and UpgradeCode that you can use to manage these scenarios: The UpgradeCode is like an application id and shouldn't change between versions; the PackageCode identifies a release of your setup and the ProductCode identifies a release of your software. You can change the ProductCode by incrementing the ProductVersion value.

Windows uses the ProductCode to see if the application is already installed on a system. If you reinstall using an installer with the same ProductCode and PackageCode you get a Repair/Uninstall option.

Rik Garner
Thanks Rik, but how can I get to a previous version's ProductCode or PackageCode or etc.?
Andrei
There's a tool called Orca, which is part of the Windows SDK (I think), which is a low-level msi editor. You should be able to inspect a previous MSI package to get at the details.
Rik Garner
How would I use that information in code I mean?
Andrei
A: 

I've eventually also figured out a way to check if the application is upgrading or if it is a fresh install:

  • The application leaves some information about itself in the registry (application name, version number etc.). This is usually stored within

LocalMachine\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{Application's GUID}

When the application is uninstalled that information is removed.

  • But you can check for that information when you are installing a version of your application (this can be done by adding some custom actions in the deployment project). I check it under the BeforeInstall method and look in the registry for the DisplayVersion value, like so:


RegistryKey regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{AppGUIDHere}");
string version = (string)regKey.GetValue("DisplayVersion");

  • This value will contain the version that is currently installed on your computer. If this installed version is smaller than the version of the application you are trying to install, then you follow the logic path of UPGRADING

  • If you can't find anything in the registry under that key, that means that this is a fresh install (there is no other application before this one installed on the computer). And here you follow the other logic path of just installing

Hope this helps somebody.

Andrei
Out of interest, is that DisplayVersion the value from the ProductVersion setting in the installer package?
Rik Garner
I don't think that is where the application gets the DisplayVersion (because it doesn't have the same format, i.e. DisplayVersion has 4 dots separating the major/minor etc. versions). I think it takes it from some AssemblyInfo.cs file within the project.
Andrei