MSI 安装程序取消不起作用
我有一个 MSI 安装程序(设置项目),它实际上通过 system.diagnostic.process 调用 Windows 窗体 exe。
该表单实际上接受用户的输入来恢复 sql server 中的 .bak 文件。
但如果发生任何异常,我无法取消设置。即使单击安装程序的取消按钮,安装回滚也不会开始。
请建议如何处理。
I have an MSI installer (set-up project) which actually calls a Windows Forms exe through system.diagnostic.process.
This form actually takes input from the user to restore a .bak file in sql server.
But if any exception occur, I am not able to cancel the setup. Even after clicking the cancel button of installer the installation roll-back will not start.
Please suggest how to handle it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建调用 Windows 窗体 exe 的新项目并向其添加安装程序类,或者仅将安装程序类添加到 Windows 窗体 exe(您必须更改其输出类型并对其进行一些修改,因此,例如,没有Main() 方法,或未设置启动对象,并且从安装操作内部调用您的表单)
安装程序类应如下所示:
当您准备好安装程序项目时,转到安装项目自定义操作并添加主要输出您的安装程序项目进行安装,提交、回滚和卸载“文件夹”。
另一个有用的事情是获取应用程序的安装目录并将其路径传递给安装程序类。您将自定义操作的 CustomActionData 属性设置为,
并在安装程序类中使用以下命令获取目录:
编辑:如果从 Install 方法中引发异常,安装将被取消。据我所知,这是在中间“取消”安装的唯一方法。您必须创建一个异常并抛出它。例如像这样:
当然,如果异常是由其他东西抛出的(我的意思是,不是您自愿“创建”的),回滚也应该开始。但是,如果您进行一些自定义更改,则必须从自定义操作的安装程序的安装方法中抛出它。
抱歉,如果我说得太详细了,但我已经解决了自己的一系列麻烦,所以如果我能帮助别人避免它,我会很高兴:)
Create new project that calls your windows forms exe and add installer class to it, or just add installer class to your windows forms exe (you'll have to change it's output type and modify it a little, so, for example, there is no Main() method, or startup object is not set, and your form is called from inside of install action)
Installer class should look like this:
When you have your installer project ready, go to your setup project Custom Action and add primary output of your installer project to its install, commit, rollback and uninstall "folders".
Another usefull thing is getting the directory in which your app is being installed and passing its path to your installer class. you do this setting CustomActionData property of your custom action to
and in your installer class you get the directory using:
EDIT: And installation will be canceled if an exception is thrown from within the Install method. As far as I know it's the only way to "cancel" your installation in the middle. You have to create an exception and throw it., for example like this:
Of course, if the exception was thrown by something else (I mean, not willingly "created" by you) the rollback shoud also start. But if you do some custom changes, it has to be thrown from within the custom action's installer's install method.
Sorry if I was a bit too detailed but I got through my own set of troubles over this so I'll be happy if I can help someone to avoid it :)