解决另一个版本的程序已经安装异常

Solving Another version of program is already installed exception

我正在尝试安装 windows 服务并启动它 afterwards.I 不明白为什么在几个周期(安装+卸载)之后我无法再安装或卸载该服务,因为我得到错误:

Another version of this product is already installed

Services window 中不再存在该服务,Programs 部分中也不存在安装程序。

如果我尝试卸载我得到:

Error 1001: An exception occured while uninstalling.This exception will be ignored and the uninstall will continue.However the uninstall might not be fully uninstalled after the uininstall is complete.

我不明白我做错了什么。 我已将我的项目输出添加到所有自定义操作:

-Install
-Uninstall
-Commit
-Rollback

一个人应该如何进行清洁installs/uninstalls?

安装程序代码

    [RunInstaller(true)]
    public partial class ProjectInstaller : Installer {
        public ProjectInstaller() {
            InitializeComponent();
            this.AfterInstall += ProjectInstaller_AfterInstall;
            this.BeforeUninstall += ProjectInstaller_BeforeUninstall;
        }

        private void ProjectInstaller_AfterInstall(object sender, InstallEventArgs e) {
            StartService();
        }

        private void ProjectInstaller_BeforeUninstall(object sender, InstallEventArgs e) {
            StopService();
        }

        private void StartService() {
            Debugger.Launch();
            bool isAdmin = IsAdmin();
            if (isAdmin) {
                using (ServiceController controller = new ServiceController(serviceInstaller1.ServiceName)) {
                    controller.Start();
                }
            } else {
                ProcessStartInfo info = new ProcessStartInfo {
                    Verb = "runas",
                    FileName = "net",
                    Arguments = $"start {serviceInstaller1.ServiceName}"
                };
                Process.Start(info);
            }
        }

        private void StopService() {
            bool isAdmin = IsAdmin();
            if (isAdmin) {
                using (ServiceController controller = new ServiceController(serviceInstaller1.ServiceName)) {
                    controller.Stop();
                }
            } else {
                ProcessStartInfo info = new ProcessStartInfo {
                    Verb = "runas",
                    FileName = "net",
                    Arguments = $"stop {serviceInstaller1.ServiceName}"
                };
                Process.Start(info);
            }
        }

        private static bool IsAdmin() {
           var identity = WindowsIdentity.GetCurrent();
           var princ = new WindowsPrincipal(identity);
           return princ.IsInRole(WindowsBuiltInRole.Administrator);
        }
}

TEMP: Adding this answer, not sure it is relevant until we hear more comments from OP.


Custom Actions: MSI has built-in mechanisms to start / stop and install / uninstall services that are quite reliable. These involve populating a number of standard MSI tables. Using custom actions could trigger problems like you describe, that are hard to debug and solve.


部署工具:您使用的是什么工具?

  • (其中之一缺少 built-in 服务安装支持)。
  • 免费和开源 WiX - here is a quick start tip answer
  • Commercial tools (Advanced Installer, Installshield, PACE, 等等...) 对大多数事情都非常好,尤其是捆绑先决条件之类的东西。

WiX 工具集:WiX 是免费的开源替代品,您还可以查看其他几种主要的部署工具。 Advanced Installer 有一些免费功能,但我认为其中不包括服务安装。值得一试 - 不错的功能。据我所知,Installshield 没有免费版本,但是 full-featured。 PACE 套件是这个街区的新生事物。我会测试它们并选择一个 - 只需 2 美分。

WiX:服务安装示例