Monday, May 20, 2013

Executing Custom Actions on the basis of Feature Selection.

I came across this situation that my user has to make selection from Customize Dialog (shows feature tree) and depending upon this selection Custom Actions (actually calls to RegSvr32.exe) have to be executed.

For this, I added a Feature Structure to be shown to user as a Choice options:

    <Feature Id="RegShellExtensions" Level="1" Display="expand" Title="Register Shell Extensions" Description="Register shell extensions with windows" >
<
FeatureId="ShellExtx86" Title="32 Bit Shell Extensions" Description="Register 32 Bit Shell Extensions" Level="1" />
<?
if $(var.PACKAGE_TARGETPLATFORM)=x64?>
<
Feature Id="ShellExtx64" Title="64 Bit Shell Extensions" Description="Register 64 Bit Shell Extensions" Level="1" />
<?
endif?>
</
Feature>


So depending upon which feature user would select, it is referenced in InstallExecuteSequence table to schedule the CustomActions accordingly:


    <InstallExecuteSequence>
      <
Custom Action="RegisterIsmShellMenu" After="CostFinalize">
        <![CDATA[
(NOT Installed) AND (&ShellExtx86=3) AND NOT(!ShellExtx86=3)]]>
      </
Custom>
     
      <?
if $(var.PACKAGE_TARGETPLATFORM)=x64?>
        <
Custom Action="RegisterIsmShellMenuX86" After="CostFinalize">
          <![CDATA[
(NOT Installed) AND (&ShellExtx64=3) AND NOT(!ShellExtx64=3)]]>
        </
Custom>
      <?
endif?>
    </
InstallExecuteSequence>


Important:The term "&ShellExtx86=3" means the action is to install the feature local. The term "NOT(!ShellExtx86=3)" means the feature is not installed local.


For more examples, see Examples of Conditional Statement Syntax.


For Conditional Statement Syntax, see Conditional Statement Syntax

No comments: