Welcome, Guest! Registration

loc2log

Thursday, 2024-03-28
Main » 2016 » July » 3 » Create custom install/uninstall actions on WiX wxs msi
3:09 PM
Create custom install/uninstall actions on WiX wxs msi

Here is how to create custom actions to be called at install and uninstall in WiX (msi). You may need to call your own scripts at install or uninstall to do some setup or cleanup. Here is wss example how to do it in the overall wxs structure:

<?xml version="1.0" encoding="utf-8"?>
<Wix ...>
  <Product ...>
    <Package ... />
    <Media ... />
    <Directory>
    ...
    </Directory>
    <SetDirectory ... />
    <Feature ...>
      <ComponentRef .../>
      ...
    </Feature>
    <UI />
    <!-- Custom actions begin -->
    <InstallExecuteSequence>
    <Custom Action="MyActionInstallName" After="InstallFiles">(NOT Installed) AND (NOT REMOVE)</Custom>
    <Custom Action="MyActionUninstallName" Before="InstallFiles">(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")</Custom>
    </InstallExecuteSequence>
    <CustomAction Id="MyActionInstallName" Return="check" Impersonate="no" Execute="deferred" Directory="TARGETDIR" ExeCommand="MyInstallCommand"/>
    <CustomAction Id="MyActionUninstallName" Return="check" Impersonate="no" Execute="deferred" Directory="TARGETDIR" ExeCommand="MyUninstallCommand"/>
    <!-- Custom actions end -->
  </Product>
</Wix>

The interesting part is between <!-- Custom actions begin --> and <!-- Custom actions end -->. In the install execute sequence's <Custom ...>, it is critical to use After="InstallFiles" attribute and (NOT Installed) AND (NOT REMOVE) condition; and in the uninistall sequence Before="InstallFiles" with (NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL") as these attributes are required for proper actions sequencing and conditions are required triggering. If you won't use these conditions, the actions will be executed both on install and uninstall. The rest can be tweakied to your liking, and you will probably have to change names of items starting with "My".

References

Views: 4971 | Added by: ep | Tags: Wix, install, MSI, MS Windows | Rating: 0.0/0
Total comments: 0
Only registered users can add comments.
[ Registration | Login ]