visual-studioinstallationsetup-projectvdproj

Visual Studio Installer, perform custom action before files are copied


I am using a regular Visual Studio Setup Project to deploy a service. I need to perform a custom action before the files are copied by the installer. AFAIS all custom actions (derived from Installer ...) are performed after the files have been copied (which is kind of obvious, since they need to be executed some way).

The actual problem is, that the installer checks by itself which files are in use and stops the service before copying (btw, the dialog of the installer to stop the applications is telling rubbish - but this is a different question). Basically this is a good idea. However, after installation the service configuration is set to re-start the service if it is not running (the service control manager does this job). This configuration is a requirement, it cannot be changed permanently (only temporarily). Later during an upgrade installation this sometimes collides with the (upgrade-)installation process. So in case of an upgrade installation I want to change the (old) service configuration to not restart or even uninstall the (old) service before the files are copied to the target folder. Otherwise copying the files sometimes failes if a file is still in used (since the old service is running again (just restarted by the service control manager) as explained above). To make a long story short, I need to execute some code before the (new) files are copied by the installer.

This is a related question but the answer doesn't fit my question: Take backup of target dir before files are copied into the target directory by msi Installer


Solution

  • The actual answer seems to be: it is not possible. I didn't have the time to completely switch to WIX or similar alternatives. This is not a nice solution but it works. I solved the problem as follows: