I have a VS2008 application that includes a service project (I'll call it ServiceProject). I have the installation project (InstallationProject) set to RemovePreviousVersions. Additionally, I have Custom Actions set for InstallationProject, to Install, Commit, Rollback, and Uninstall the Primary output from ServiceProject.
Sometimes when I build new versions of the installer, I can install without an error. Often, when I get to the point of setting up the service (entering a username and password into the installer) - it fails with the error, "The specified service already exists".
I don't know why it's inconsistent, though I've considered that maybe there is some kind of signature for the service and if the service is unmodified, it is able to remove it successfully, but with modifications, it doesn't recognize the service. However, I rarely make modifications to the service, so I doubt that's it.
How can I make my installer successfully update the service without this error? My work-around is to manually go into Control Panel, uninstall the former application, then run the installer.
Make sure that the assembly version of the service and the GUID (In AssemblyInfo.vb/cs) are getting changed when you deploy each new installer package. If it detects the same version then updates fail.
Try this code in your installer class. I hope it will resolve your problem.
And also put "NOTPREVIOUSVERSIONSINSTALLED"
In addition to making sure the file versions are different as StingyJack mentioned you have another problem. From the VS documentation (sorry, not online)
So you are installing a service using a custom action - but when upgrading the Uninstall part is not being called as you expect and you are trying to Install over an existing, running version.
I think that when its asking for a reboot is because it can't update the services file whilst its running.
Two options :-
Add code to your Install/Commit custom action to Stop the service, wait for the installer to replace the services files and then restart the service. See PonalSuper3's answer in this thread
Put the VS2008 behaviour back to how it worked in VS2005 (the old versions Uninstall custom action is called before the new version Install) by using Orca to alter the InstallExecuteSequence.RemoveExistingProducts to be immediately after .InstallInitialize - usually you set the .RemoveExistingProducts to 1525 but check your individual MSI.
I've added a script than you can add to your build process to change the MSI's InstallExecuteSequence
Put "Not (Installed OR PREVIOUSVERSIONSINSTALLED)" in the Custom Actions->Install Condition property.
Something that may help but was not stated in any of the above that is related to Ryan's answer. This same problem happened to me until I did this: open the .msi in Orca and locate the Upgrade table. Where the previousversioninstalled line (was the first entry in mine) is, you should see an upgrade code. Find the .msi of the program that is currently installed (the one you want to upgrade), find the upgrade code (which you can do in orca), and copy and paste it into that upgrade table for your new .msi. This did the trick for me.