Why is it a good idea to limit the use of custom actions in my WiX / MSI setups?

后端 未结 2 730
萌比男神i
萌比男神i 2020-11-22 06:17

Why is it a good idea to limit the use of custom actions in my WiX / MSI setups?


Deployment is a crucial part of most development. Please give this content a c

2条回答
  •  佛祖请我去吃肉
    2020-11-22 06:46

    The idea that custom actions should be limited comes from the fact that it is easy to write a poorly implemented custom action. A poorly implemented custom action is one that, in the event of installation failure, cannot roll back changes already made to the system (i.e. installing a windows service, for example).

    That being said, if a custom action is written such that it has a complimentary rollback custom action in place, then I don't think its a problem.

    The pattern I like to follow is that for every "custom action" that I think I might need (for example, FoobarCustomAction), its actually 3 consists custom actions:

    • FoobarCustomActionImmediate - This is an immediate custom action that prepares 2 payloads:
      • First, a payload to pass to FoobarCustomActionDeferred, which dictates the system altering changes to make.
      • Second, a payload to pass to FoobarCustomActionRollback, which dictates how to rollback the system altering changes.
    • FoobarCustomActionRollback - This is a rollback custom action that is scheduled before FoobarCustomActionDeferred in sequence, that uses the payload provided by FoobarCustomActionImmediate to rollback the changes made by FoobarCustomActionDeferred in the event of a critical failure.
    • FoobarCustomActionDeferred - This is a deferred custom action that makes all of the system altering changes to the system.

    Like many other technologies, I think there is always a way to write poorly maintainable code in WiX. Take the example above, if this is a custom action that I want to use in many different installers, I should provide the developers a .wxs file containing a fragment that ensures all needed custom actions are referenced and sequenced correctly. If instead, the WiX code is simply copy pasted carelessly across many different installers, the chance of the custom action being implemented incorrectly increases. Its our job as developers to help consumers of our code fall into the pit of success, and I think WiX provides that through careful use of fragment and wixlibs.

    But the developer of the installer has to care about such things, WiX does not enforce it!

提交回复
热议问题