WiX. Rollback custom action when is canceled installation

﹥>﹥吖頭↗ 提交于 2019-12-10 16:36:50

问题


I have a custom action

<CustomAction Id="myActionId" BinaryKey="myAction" DllEntry="MySimpleAction" Execute="immediate" Return="check" />

<InstallExecuteSequence>
      <Custom Action="myActionId" After="InstallInitialize">CHECKBOXCOPYPROP=1</Custom>
</InstallExecuteSequence>

My custom action does backup and resolved database. I need to do rollback (drop database) when is canceled installation. I did:

<CustomAction Id="myActionId" BinaryKey="myAction" DllEntry="MySimpleAction" Execute="immediate" Return="check" />
<CustomAction Id="myActionRollbackId" BinaryKey="myActionRollback" DllEntry="MySimpleAction" Execute="rollback" Return="check" />

<InstallExecuteSequence>
      <Custom Action="myActionId" After="InstallInitialize">CHECKBOXCOPYPROP=1</Custom>
      <Custom Action="myActionRollbackId" Before="myActionId">CHECKBOXCOPYPROP=1</Custom>
</InstallExecuteSequence>

But I was having an error.

If I do like this:

<CustomAction Id="myActionId" BinaryKey="myAction" DllEntry="MySimpleAction" Execute="immediate" Return="check" />
<CustomAction Id="myActionRollbackId" BinaryKey="myActionRollback" DllEntry="MySimpleAction" Execute="immediate" Return="check" />

<InstallExecuteSequence>
      <Custom Action="myActionId" After="InstallInitialize">CHECKBOXCOPYPROP=1</Custom>
      <Custom Action="myActionRollbackId" After="myActionId">CHECKBOXCOPYPROP=1</Custom>
</InstallExecuteSequence>

My custom action myActionRollbackId works.

How to run rolback when is canceled installation? Someone can help me?


回答1:


The custom action which runs on install and does something with the database should be deferred (Execute='deferred'). Its corresponding rollback action should be Execute='rollback'. When you schedule these custom actions, the rollback action should go first.

Also, make sure the conditions are set properly.




回答2:


Installation is always done in transaction. when you launch an installer, it first creates something called installation script which is like a to do list of what it will do while installation. When we set some custom action as Execute="immediate", it gets executed immediately but when we set our action as Execute="deferred", it gets added in the installation script, hence rollback becomes easy for this. Now one thing to note here is that we get access to session in Execute="immediate" mode, but we cannot access session in Execute="deferred" mode. If we try to access session it will give error, which in this case might be the reason for your error...



来源:https://stackoverflow.com/questions/12543196/wix-rollback-custom-action-when-is-canceled-installation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!