如何最好地在WiX中定义自定义操作?
时间:2020-03-06 14:40:26 来源:igfitidea点击:
我有一个WiX安装程序和一个自定义操作(加上撤消和回滚),它使用安装程序中的属性。所有文件都放在硬盘上之后,必须执行自定义操作。似乎我们需要为此在WXS文件中输入16个条目。根内的八个,像这样:
<CustomAction Id="SetForRollbackDo" Execute="immediate" Property="RollbackDo" Value="[MYPROP]"/> <CustomAction Id="RollbackDo" Execute="rollback" BinaryKey="MyDLL" DllEntry="UndoThing" Return="ignore"/> <CustomAction Id="SetForDo" Execute="immediate" Property="Do" Value="[MYPROP]"/> <CustomAction Id="Do" Execute="deferred" BinaryKey="MyDLL" DllEntry="DoThing" Return="check"/> <CustomAction Id="SetForRollbackUndo" Execute="immediate" Property="RollbackUndo" Value="[MYPROP]"/> <CustomAction Id="RollbackUndo" Execute="rollback" BinaryKey="MyDLL" DllEntry="DoThing" Return="ignore"/> <CustomAction Id="SetForUndo" Execute="immediate" Property="Undo" Value="[MYPROP]"/> <CustomAction Id="Undo" Execute="deferred" BinaryKey="MyDLL" DllEntry="UndoThing" Return="check"/>
在" InstallExecuteSequence"中有八个,如下所示:
<Custom Action="SetForRollbackDo" After="InstallFiles">REMOVE<>"ALL"</Custom> <Custom Action="RollbackDo" After="SetForRollbackDo">REMOVE<>"ALL"</Custom> <Custom Action="SetForDo" After="RollbackDo">REMOVE<>"ALL"</Custom> <Custom Action="Do" After="SetForDo">REMOVE<>"ALL"</Custom> <Custom Action="SetForRollbackUndo" After="InstallInitialize">REMOVE="ALL"</Custom> <Custom Action="RollbackUndo" After="SetForRollbackUndo">REMOVE="ALL"</Custom> <Custom Action="SetForUndo" After="RollbackUndo">REMOVE="ALL"</Custom> <Custom Action="Undo" After="SetForUndo">REMOVE="ALL"</Custom>
有没有更好的办法?
解决方案
如果我们有需要支持回滚的复杂自定义操作,则可以考虑编写Wix扩展。扩展通常提供创作支持(即映射到MSI表条目的新XML标记),以及自动调度自定义操作。
这不仅仅是编写自定义操作,还需要做更多的工作,但是一旦CA达到了一定的复杂度,扩展提供的易于编写就值得了。
WiX自定义操作是一个很好的遵循模型。在这种情况下,我们只能通过" CustomAction"声明立即操作,延迟操作和回滚操作。我们只能通过"自定义"计划立即操作,其中将立即操作实现为本机DLL中的代码。
然后,在立即动作的代码中,调用MsiDoAction来安排回滚和延迟的动作:当延迟动作和延迟动作时,它们会在调用MsiDoAction时写入脚本,而不是立即执行。我们还需要调用MsiSetProperty
来设置自定义操作数据。
例如,下载WiX源代码并研究IISExtension的工作方式。 WiX操作通常会解析自定义表,并根据该表为延迟操作的属性生成数据。