首页 > 解决方案 > 在安装项目中执行 InstallerClass 的 Roolback 事件时找不到 installstate 错误

问题描述

我创建了一个 Visual Studio 安装项目,并将两个控制台应用程序作为项目输出添加到安装项目。每个控制台应用程序都有其安装程序类。在安装项目的自定义操作中,我添加了以上两个应用程序。

在 consoleApp2 的 InstallerClass 中我有一些验证,如果验证成功,那么它将验证 ConsoleApp1 的 InstallerClass,否则应该回滚安装程序安装。

在回滚操作期间,我收到“错误 1001。找不到文件应用程序路径\Consoleapp1.InstallState”,如下所示,因为它的安装状态尚未启动。

在此处输入图像描述

有什么办法可以解决这个问题。如果安装程序类中的验证失败,我的主要座右铭是回滚安装而不向用户显示错误。下面是我正在使用的代码。

  public override void Install(IDictionary stateSaver)
    {
        base.Install(stateSaver);
        MessageBox.Show("Install");
        try
        {
            const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\";

            using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(subkey))
            {
                if (ndpKey != null && ndpKey.GetValue("Release") != null && Convert.ToInt32(ndpKey.GetValue("Release")) > 461310)
                {
                    MessageBox.Show("Framework version is " + ndpKey.GetValue("Release").ToString());

                    string message = "This setup requires .Net framework Version 4.7.1. Please install the .Net Framework and run setup again. The .Net framework can be  obtained from the web. Would you like to do this now ?";
                    MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                    DialogResult result = MessageBox.Show(message, "", buttons);
                    if (result == DialogResult.Yes)
                    {
                        Process.Start("http://go.microsoft.com");

                        throw new InstallException(String.Format("Installation rollbacked."));
                    }
                    else
                    {
                        throw new InstallException(String.Format("Cancelling Installation"));

                    }

                }
                else
                {


                }

            }
        }
        catch (Exception ex)
        {

            throw new Exception(String.Format("Cancelling Installation 123"));

        }

    }
    public override void Rollback(IDictionary savedState)
    {
        base.Rollback(savedState);
        MessageBox.Show("rollback c2 " + savedState.Values);
    }
    public override void Uninstall(IDictionary savedState)
    {
        base.Uninstall(savedState);
    }
    public override void Commit(IDictionary savedState)
    {
        base.Commit(savedState);
    }

标签: c#setup-projectcustom-actionuninstallation

解决方案


推荐阅读