我想恢复使用ClickOnce发布的以前版本的C#应用程序,如果数据库迁移失败,因为数据库不是最新的,并且它不支持最新版本的应用程序.
细节
我正在开发一个应用程序,将在没有互联网的偏远地区本地使用.一个人会偶尔以某种方式通过互联网更新他/她的应用程序,然后将在本地网络上部署该应用程序.从那里每个人都可以获得更新版本的应用程序.我现在想要的是使用此应用程序使用数据库迁移,如果应用程序失败它应该还原到以前的版本.我已经使用FluentMigrator进行数据库迁移,并使用ClickOnce来部署应用程序.我也经历过这里的几乎所有链接,看看我该怎么做.我现在知道使用ClickOnce是不可能的.任何人都可以通过其他方式告诉我或者可能是某种黑客攻击吗?我正在使用ClickOnce,因为它具有自动更新功能,所以现在不想丢失该功能.任何帮助将不胜感激.
FluentMigrator 跟踪数据库中的当前版本。它还跟踪当前应用程序版本中的最新版本。运行 Migrator 函数并检查当前版本中的迁移文件的最新版本是否等于数据库中存储的最新版本。如果两者相等则迁移成功。如果不相等则可以运行cmd命令直接打开(删除或备份)控制面板窗口并转到以前的版本。这是使用 ClickOnce 恢复到以前版本的最佳方法。
try {
new MigrationsWrapper(AppManager.ConnectionString).MigrateToLatestVersion();
}
catch (Exception ex)
{
}
LatestVersionNumber = new MigrationsWrapper(AppManager.ConnectionStringADO).LatestVersionNumber;
CurrentVersionNumber = new MigrationsWrapper(AppManager.ConnectionStringADO).CurrentVersionNumber;
if (LatestVersionNumber > CurrentVersionNumber) {
string applicationName = ConfigurationManager.AppSettings["ApplicationName"].ToString();
string uninstallString = GetUninstallRegistryKeyByProductName(applicationName);
if (uninstallString != string.Empty) {
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/c " + uninstallString;
process.StartInfo = startInfo;
process.Start();
}
} else {
// Successfull
}
Run Code Online (Sandbox Code Playgroud)