当我安装新版本的软件时,如何消除“指定的服务已经存在”?

时间:2022-03-11 07:15:53

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.

我有一个VS2008应用程序,其中包括一个服务项目(我称之为ServiceProject)。我将安装项目(InstallationProject)设置为RemovePreviousVersions。此外,我为InstallationProject设置了自定义操作,从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.

如何在没有此错误的情况下使安装程序成功更新服务?我的解决方法是手动进入控制面板,卸载以前的应用程序,然后运行安装程序。

5 个解决方案

#1


In addition to making sure the file versions are different as StingyJack mentioned you have another problem. From the VS documentation (sorry, not online)

除了确保文件版本不同,StingyJack提到你还有另一个问题。来自VS文档(抱歉,不在线)

If you have set both install and uninstall custom actions in an application's setup project, and you have enabled the RemovePreviousVersions property in Visual Studio 2005, the previous version of the product is uninstalled during an upgrade. However, this behavior changed in Visual Studio 2008 as follows:

如果在应用程序的安装项目中设置了安装和卸载自定义操作,并且在Visual Studio 2005中启用了RemovePreviousVersions属性,则在升级期间将卸载以前版本的产品。但是,此行为在Visual Studio 2008中更改如下:

In Visual Studio 2005, the custom actions were called as follows on an upgrade from v1.0.0 to v1.0.1:

在Visual Studio 2005中,从v1.0.0升级到v1.0.1时,自定义操作的调用如下:

v1.0.0 custom action Uninstall()

v1.0.0自定义操作卸载()

v1.0.1 custom action Install()

v1.0.1自定义操作Install()

In Visual Studio 2008, the uninstall action is not called, as follows:

在Visual Studio 2008中,未调用卸载操作,如下所示:

v1.0.1 custom action Install()

v1.0.1自定义操作Install()

If you created custom actions relying on the old behavior, you need to modify your code for the new behavior. This behavior change affects only updates, not uninstalls.

如果您依赖于旧行为创建了自定义操作,则需要修改新行为的代码。此行为更改仅影响更新,而不影响卸载。

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

在安装/提交自定义操作中添加代码以停止服务,等待安装程序更换服务文件,然后重新启动服务。请参阅PonalSuper3在此主题中的答案

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.

通过使用Orca将InstallExecuteSequence.RemoveExistingProducts更改为紧跟在.InstallInitialize之后,将VS2008行为恢复到它在VS2005中的工作方式(在新版本安装之前调用旧版本卸载自定义操作) - 通常将.RemoveExistingProducts设置为1525但请检查您的个人MSI。

I've added a script than you can add to your build process to change the MSI's InstallExecuteSequence

我添加了一个脚本,而不是添加到构建过程中以更改MSI的InstallExecuteSequence

#2


Put "Not (Installed OR PREVIOUSVERSIONSINSTALLED)" in the Custom Actions->Install Condition property.

将“Not(已安装或PREVIOUSVERSIONSINSTALLED)”放入“自定义操作” - >“安装条件”属性中。

#3


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.

部署每个新的安装程序包时,请确保更改服务的程序集版本和GUID(在AssemblyInfo.vb / cs中)。如果它检测到相同版本,则更新失败。

#4


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.

可能有所帮助,但上述任何与Ryan的答案无关的内容都没有说明。直到我这样做才发生同样的问题:打开Orca中的.msi并找到升级表。如果previousversion安装的行(是我的第一个条目)是,您应该看到升级代码。找到当前安装的程序的.msi(要升级的程序),找到升级代码(可以在orca中执行),然后将其复制并粘贴到新的.msi的升级表中。这对我有用。

#5


Try this code in your installer class. I hope it will resolve your problem.

在安装程序类中尝试此代码。我希望它能解决你的问题。

protected override void OnBeforeInstall(IDictionary savedState)
        {
            if (LaunchOnBeforeInstall())
            {
                base.OnBeforeInstall(savedState);
            }
            else
            {
                throw new Exception("You cancelled installation");
            }
        }
        public bool LaunchOnBeforeInstall()
        {
            Form2 frm2 = new Form2();
            DialogResult result = frm2.ShowDialog();
            if (result == DialogResult.Cancel)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

And also put "NOTPREVIOUSVERSIONSINSTALLED" 当我安装新版本的软件时,如何消除“指定的服务已经存在”?

并且还说“NOTPREVIOUSVERSIONSINSTALLED”

#1


In addition to making sure the file versions are different as StingyJack mentioned you have another problem. From the VS documentation (sorry, not online)

除了确保文件版本不同,StingyJack提到你还有另一个问题。来自VS文档(抱歉,不在线)

If you have set both install and uninstall custom actions in an application's setup project, and you have enabled the RemovePreviousVersions property in Visual Studio 2005, the previous version of the product is uninstalled during an upgrade. However, this behavior changed in Visual Studio 2008 as follows:

如果在应用程序的安装项目中设置了安装和卸载自定义操作,并且在Visual Studio 2005中启用了RemovePreviousVersions属性,则在升级期间将卸载以前版本的产品。但是,此行为在Visual Studio 2008中更改如下:

In Visual Studio 2005, the custom actions were called as follows on an upgrade from v1.0.0 to v1.0.1:

在Visual Studio 2005中,从v1.0.0升级到v1.0.1时,自定义操作的调用如下:

v1.0.0 custom action Uninstall()

v1.0.0自定义操作卸载()

v1.0.1 custom action Install()

v1.0.1自定义操作Install()

In Visual Studio 2008, the uninstall action is not called, as follows:

在Visual Studio 2008中,未调用卸载操作,如下所示:

v1.0.1 custom action Install()

v1.0.1自定义操作Install()

If you created custom actions relying on the old behavior, you need to modify your code for the new behavior. This behavior change affects only updates, not uninstalls.

如果您依赖于旧行为创建了自定义操作,则需要修改新行为的代码。此行为更改仅影响更新,而不影响卸载。

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

在安装/提交自定义操作中添加代码以停止服务,等待安装程序更换服务文件,然后重新启动服务。请参阅PonalSuper3在此主题中的答案

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.

通过使用Orca将InstallExecuteSequence.RemoveExistingProducts更改为紧跟在.InstallInitialize之后,将VS2008行为恢复到它在VS2005中的工作方式(在新版本安装之前调用旧版本卸载自定义操作) - 通常将.RemoveExistingProducts设置为1525但请检查您的个人MSI。

I've added a script than you can add to your build process to change the MSI's InstallExecuteSequence

我添加了一个脚本,而不是添加到构建过程中以更改MSI的InstallExecuteSequence

#2


Put "Not (Installed OR PREVIOUSVERSIONSINSTALLED)" in the Custom Actions->Install Condition property.

将“Not(已安装或PREVIOUSVERSIONSINSTALLED)”放入“自定义操作” - >“安装条件”属性中。

#3


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.

部署每个新的安装程序包时,请确保更改服务的程序集版本和GUID(在AssemblyInfo.vb / cs中)。如果它检测到相同版本,则更新失败。

#4


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.

可能有所帮助,但上述任何与Ryan的答案无关的内容都没有说明。直到我这样做才发生同样的问题:打开Orca中的.msi并找到升级表。如果previousversion安装的行(是我的第一个条目)是,您应该看到升级代码。找到当前安装的程序的.msi(要升级的程序),找到升级代码(可以在orca中执行),然后将其复制并粘贴到新的.msi的升级表中。这对我有用。

#5


Try this code in your installer class. I hope it will resolve your problem.

在安装程序类中尝试此代码。我希望它能解决你的问题。

protected override void OnBeforeInstall(IDictionary savedState)
        {
            if (LaunchOnBeforeInstall())
            {
                base.OnBeforeInstall(savedState);
            }
            else
            {
                throw new Exception("You cancelled installation");
            }
        }
        public bool LaunchOnBeforeInstall()
        {
            Form2 frm2 = new Form2();
            DialogResult result = frm2.ShowDialog();
            if (result == DialogResult.Cancel)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

And also put "NOTPREVIOUSVERSIONSINSTALLED" 当我安装新版本的软件时,如何消除“指定的服务已经存在”?

并且还说“NOTPREVIOUSVERSIONSINSTALLED”