Search code examples
wixwix-extension

How can I optionally install IIS virtual directory with WiX Toolset?


I'm trying to optionally install a virtual directory if IIS is installed. If it's not installed, then just skip it.

I've got this check:

<Fragment>
  <Property Id="IIS_MAJOR_VERSION">
    <RegistrySearch Id="CheckIISVersion"
                    Root="HKLM"
                    Key="SOFTWARE\Microsoft\InetStp"
                    Name="MajorVersion"
                    Type="raw" />
  </Property>

  <iis:WebSite Id='DefaultWebSite' Description='Default Web Site' Directory='INSTALLFOLDER'>
    <iis:WebAddress Id="AllUnassigned" Port="80" />
  </iis:WebSite>

</Fragment>

and based on the IIS_MAJOR_VERSION being present, I install the feature:

<Feature Id="ProductFeature2" Title="Setup" Level="1">
  <ComponentRef Id="AppIIS" />
  <Condition Level="0">NOT IIS_MAJOR_VERSION</Condition>
</Feature>

This part seems to work, however, the iis:WebSite node is causing issues. I only want to locate it if IIS_MAJOR_VERSION is present as well.

If I move the iis:WebSite node into the component group it works, but then iis:WebSite is not in 'locator' mode and gets installed and uninstalled (which is bad).

Is there a way I can conditionally run the check for iis:WebSite?


Solution

  • When you add any element from IIS extension (like <iis:WebSite>), a special custom action called ConfigureIIs is added to the InstallExecuteSequence table. This custom action is a so-called entry point to everything related to IIS management with the help of WiX IIS extension.

    Fortunately, ConfigureIIs custom action is conditioned by default the way to skip it if need be. If you open the resulting MSI package with Orca and navigate to InstallExecuteSequence table on the left pane, you'll see the condition uses SKIPCONFIGUREIIS property. Thus, the idea is to set it to something (e.g. 1) in case you don't need to perform any IIS related activities.

    It can be done with SetProperty element:

    <SetProperty Id="SKIPCONFIGUREIIS" Value="1">NOT IIS_MAJOR_VERSION</SetProperty>