c# - 在安装项目中执行 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);
}
解决方案
推荐阅读
- kubernetes - 具有来自 Prometheus 的自定义指标的 Horizontal Pod Autoscaler 以及 CPU 使用率的百分位数
- c# - 如何在 c# 控制器中对 HTTP 响应/请求进行单元测试?
- json - 如何反序列化 cypress JSON 请求
- swift - 将公共函数的实现隐藏在私有函数中是否有任何性能优势或编译时间改进
- svn - 在 TortoiseSVN / 分支实践中合并特定文件
- data-structures - 单链表的正确实现是什么?
- javascript - 使用正则表达式从日期产生年份和月份
- android - 无法使用 YoutubePlayerSupportFragment 进行 FragmentTransaction
- c++ - Visualstudio / cmake启动json文件获取的$ {relativeFile}不包括反斜杠
- java - 更新 Android Studio 后链接引用资源和重复值失败