简体   繁体   English

如何在自定义操作中回滚卸载?

[英]How to rollback uninstallation in custom action?

I am displaying a MessageBox in OnBeforeUninstall override in custom installer class. 我在自定义安装程序类的OnBeforeUninstall覆盖中显示MessageBox

I have assigned the installer class to Uninstall in Custom Action Editor of Visual studio setup project. 我已将安装程序类分配给Visual Studio安装项目的“自定义操作编辑器”中的“ Uninstall ”。

Now based on dialog result, I need to rollback the uninstallation? 现在基于对话框结果,我需要回滚卸载吗?

I have read this but these are specific to Installshield. 我已经读过了,但是这些是Installshield特有的。 I need to do it in Visual Studio setup project. 我需要在Visual Studio安装项目中执行此操作。

I have tried Process.GetCurrentProcess().Kill() but it puts the installation in unstable state. 我已经尝试过Process.GetCurrentProcess().Kill()但是它使安装处于不稳定状态。

I have also tried this.Rollback() but it shows following error 我也尝试过this.Rollback()但它显示以下错误

Error 1001. An exception occured while uninstalling. 错误1001。卸载时发生异常。 This exception will be ignored and the uninstall will continue. 该异常将被忽略,卸载将继续。 However, the application might not be fully uninstalled after the uninstall is complete. 但是,卸载完成后,该应用程序可能未完全卸载。 -> The savedState parameter cannot be null." -> saveState参数不能为null。”

If the Messagebox in the Installer project is in shown during the Install override. 如果在安装覆盖期间显示安装程序项目中的消息框。 Then if you 那如果你

throw new InstallException();

The Rollback override will execute. 将执行回滚替代。

{MyInstallerProject} > RightClick > Add Project Output > Choose Project from Drop Down > Choose Primary Output > OK. {MyInstallerProject}>右键单击>添加项目输出>从下拉菜单中选择项目>选择主要输出>确定。 View | 查看| CustomActions > Right Click Install > Add Custom Action > Double Click Application Folder > Choose 'primary output from {CustomActionprojectname} (Active)' CustomActions>右键单击安装>添加自定义操作>双击应用程序文件夹>选择“来自{CustomActionprojectname}的主要输出(活动)”

Repeat but for "Rollback" instead of "Install" in above instructions. 重复上述步骤,但对“回滚”而不是“安装”进行重复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM