visual-studio - 安装新版本软件时如何消除 "The specified service already exists"?

标签 visual-studio windows-services installation

我有一个 VS2008 应用程序,其中包含一个服务项目(我称之为 ServiceProject)。我将安装项目 (InstallationProject) 设置为 RemovePreviousVersions。此外,我设置了自定义操作 对于 InstallationProject,用于安装、提交、回滚和卸载 ServiceProject 的主输出。

有时,当我构建新版本的安装程序时,我可以安装而不会出现错误。通常,当我设置服务(在安装程序中输入用户名和密码)时 - 它会失败并出现错误, “指定的服务已经存在” .

我不知道为什么不一致,虽然我考虑过服务可能有某种签名,如果服务未修改,它可以成功删除它,但修改后,它无法识别服务。但是,我很少对服务进行修改,所以我怀疑就是这样。

如何让我的安装程序成功更新服务而不会出现此错误? 我的解决方法是手动进入控制面板,卸载以前的应用程序,然后运行安装程序。

最佳答案

除了像 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:

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

v1.0.0 custom action Uninstall()

v1.0.1 custom action Install()

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

v1.0.1 custom action 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.



因此,您正在使用自定义操作安装服务 - 但是在升级 Uninstall 部分时未按预期调用,并且您正在尝试在现有的、正在运行的版本上进行安装。

我认为当它要求重新启动是因为它在运行时无法更新服务文件。

两种选择:-

将代码添加到您的安装/提交自定义操作以停止服务,等待安装程序替换服务文件,然后重新启动服务。见 PonalSuper3's answer in this thread

Put the VS2008 behaviour back to how it worked in VS2005 (旧版本卸载自定义操作在新版本安装之前调用)通过使用 Orca 将 InstallExecuteSequence.RemoveExistingProducts 更改为紧跟在 .InstallInitialize 之后 - 通常您将 .RemoveExistingProducts 设置为 1525,但请检查您的个人 MSI。

我添加了一个 script than you can add to your build process to change the MSI's InstallExecuteSequence

关于visual-studio - 安装新版本软件时如何消除 "The specified service already exists"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/451573/

相关文章:

visual-studio - 如何通过 Visual Studio 2019、2017 和 2015 为 Windows 10 UWP 应用程序创建有效的可信和/或自签名证书

windows - 在命令行中编译库时出错

c# - 服务与流程

installation - Wix 非管理员安装程序教程?

opencv - 在 Visual Studio 2012 中安装 OpenCV

c# - Visual Studio 中方形/菱形断点的含义是什么?

c++ - MySQL C++ 连接器 Unresolved 依赖项 (VS 2015)

c# - OnStart() 未被调用。服务进程无法连接到服务 Controller 。手动工作,并在其他机器上工作

c++ - 使用 sc 工具区分作为系统重启一部分的 Windows 服务启动和服务停止/启动

eclipse - 如何在 Eclipse 中安装 PyDev 2.8.2