Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add an Application to an existing IIS Site using WiX

I am wanting to add an Application to an existing IIS Site which is not the default IIS Site. This is not a usual request, but is required when deploying to a Win 2008 SBS, MVC Web API applications must be moved under 'SBS Web Applications' to work correctly.

In IIS, I would right mouse button on the 'SBS Web Applications' > Add Application... and set the Alias, Application Pool & Physical Path.

Wix does not allow me to set these properties on an IIS:WebApplication, further more it looks like I need to use a IIS:WebVirtualDir, but I don't want or need to do this. I simply need to point the Physical Path attribute to where my API is installed for this to work.

Why can't I tell the WiX IIS:WebApplication the Alias & Path that I want as per the IIS UI?

Of all the WiX work I have done, I would have thought this would have been one of the easier things to do.

Note: I want to create the Application, I don't want or need to create the Site - it's already there.

like image 413
user2045054 Avatar asked Feb 05 '13 23:02

user2045054


1 Answers

You can achieve the specified goals with WIX. I have even more complex variant: installing either to new Web site or existing one, for IIS 6, IIS 7 and IIS 7.5.

As for installing into existing web site, WIX identifies the site based on SiteId. If your site has non-autogenerated ID, you need to specify it explicitly instead of setting * in the corresponding field. Otherwise siteId is generated based on it's Description attribute, so you need to specify description correctly to reference the existing site.

Here follows my implementation (I hope you can extract what you need from it):

<PropertyRef Id="FRAMEWORKROOT"/>

<PropertyRef Id="SITE_INSTALL_MODE"/>
<PropertyRef Id="SITE_NAME"/>
<PropertyRef Id="SITE_PORT"/>
<PropertyRef Id="SITE_VIRT_DIR"/>
<PropertyRef Id="SITE_APP_NAME"/>
<PropertyRef Id="SITE_HEADER"/>
<PropertyRef Id="SITE_APP_POOL"/>
<PropertyRef Id="SITE_ID"/>

<Property Id="SITE_APP_NAME" Value="{ProductId}"/>

<iis:WebApplication Id="IIS6WebApp" Name="[SITE_APP_NAME]" WebAppPool="AppPool" >
  <iis:WebApplicationExtension Verbs="GET,HEAD,POST" CheckPath="no" Script="yes" Executable="[FRAMEWORKROOT]v4.0.30319\aspnet_isapi.dll" />
</iis:WebApplication>

<iis:WebApplication Id="Iis7WebApp" Name="[SITE_APP_NAME]" WebAppPool="AppPool"></iis:WebApplication>

<iis:WebSite Id="ExistingWebSite" Description="[EXISTING_SITE_NAME]" SiteId="*">
  <iis:WebAddress Id="ExistingSite_IIS7_Header_Binding" Port="[SITE_PORT]" Header="[SITE_HEADER]" />
</iis:WebSite>

<util:Group Id="IisUsersGroup" Name="[IisGroup]" Domain="[ComputerName]"/> 

<DirectoryRef Id="SITE_INSTALLDIR">
  <Component Id="AppPoolConfigure" Guid="YOURGUID-5549-48E8-B989-AFC61D279527" KeyPath="yes" Permanent="no">
    <util:User Id="SiteUser" Domain="[APP_USER_DOMAIN]" Name="[APP_USER_NAME]" Password="[APP_USER_PASSWORD]" CreateUser="no" UpdateIfExists="no" RemoveOnUninstall="no">
      <util:GroupRef Id="IisUsersGroup"/>
    </util:User>

    <iis:WebAppPool Id="AppPool" Name="[SITE_APP_POOL]" ManagedRuntimeVersion="v4.0" ManagedPipelineMode="integrated" Identity="other" User="SiteUser" />
  </Component>

  <Component Id="Iis6NewSiteConfigure" Guid="YOURGUID-8592-4E69-8D80-E42745307D7A" KeyPath="yes" Permanent="no">
    <Condition><![CDATA[Installed OR (SITE_INSTALL_MODE = "NewSite" AND IISMAJORVERSION AND (IISMAJORVERSION = "#6"))]]></Condition>
    <iis:WebSite Id="NewWebSite_IIS6" Description="[SITE_NAME]"
                 AutoStart="yes" StartOnInstall="yes" ConfigureIfExists="no"
                 Directory="SITE_INSTALLDIR" ConnectionTimeout="360" SiteId="[SITE_ID]" 
                 DirProperties="WebDirProperties" WebApplication="IIS6WebApp">
      <iis:WebAddress Id="Site_IIS6_Header_Bindings" Port="[SITE_PORT]" Header="[SITE_HEADER]" />
    </iis:WebSite>
  </Component>

  <Component Id="Iis6ExistingSiteConfigure" Guid="YOURGUID-8ECB-4AC3-95B1-B7287D0AC903" KeyPath="yes" Permanent="no">
    <Condition><![CDATA[Installed OR (SITE_INSTALL_MODE = "ExistingSiteNewVDir" AND IISMAJORVERSION AND (IISMAJORVERSION = "#6"))]]></Condition>
      <iis:WebVirtualDir Id="Site_IIS6_VDir" Directory="SITE_INSTALLDIR" Alias="[SITE_VIRT_DIR]" WebSite="ExistingWebSite" 
                         DirProperties="WebDirProperties" WebApplication="IIS6WebApp"/>
  </Component>

  <Component Id="Iis6ConfigExtentions" Guid="YOURGUID-55F2-48E3-8B08-E37BA5137D8D" KeyPath="yes" Permanent="yes">
    <Condition><![CDATA[Installed OR (IISMAJORVERSION AND (IISMAJORVERSION = "#6"))]]></Condition>
    <iis:WebServiceExtension Id="ExtensionASP4" Group="ASP.NET v4.0.30319" Allow="yes" File="[FRAMEWORKROOT]v4.0.30319\aspnet_isapi.dll" Description="ASP.NET v4.0.30319"/>
  </Component>

  <Component Id="Iis7NewSiteConfigure" Guid="YOURGUID-5DF6-4071-94F4-89D1EDAE8D90" KeyPath="yes" Permanent="no">
    <Condition><![CDATA[Installed OR (SITE_INSTALL_MODE = "NewSite" AND IISMAJORVERSION AND (IISMAJORVERSION > "#6"))]]></Condition>
    <iis:WebSite Id="WebSite_IIS7" Description="[SITE_NAME]"
                 AutoStart="yes" StartOnInstall="yes" ConfigureIfExists="yes"
                 Directory="SITE_INSTALLDIR" ConnectionTimeout="360" SiteId="[SITE_ID]"
                 DirProperties="WebDirProperties" WebApplication="Iis7WebApp">
      <iis:WebAddress Id="NewSite_IIS7_Header_Binding" Port="[SITE_PORT]" Header="[SITE_HEADER]" />
    </iis:WebSite>
  </Component>

  <Component Id="Iis7ExistingSiteConfigure" Guid="YOURGUID-FBBE-4379-8C7B-CDBD08EDCBA2" KeyPath="yes" Permanent="no">
    <Condition><![CDATA[Installed OR (SITE_INSTALL_MODE = "ExistingSiteNewVDir" AND IISMAJORVERSION AND (IISMAJORVERSION > "#6"))]]></Condition>
      <iis:WebVirtualDir Id="Site_IIS7_VDir" Directory="SITE_INSTALLDIR" Alias="[SITE_VIRT_DIR]" WebSite="ExistingWebSite"
                         DirProperties="WebDirProperties" WebApplication="Iis7WebApp"/>
  </Component>
</DirectoryRef>

<ComponentGroup Id="IisSiteOrVDirCreate">
  <ComponentRef Id="AppPoolConfigure"/>
  <ComponentRef Id="Iis6NewSiteConfigure"/>
  <ComponentRef Id="Iis6ExistingSiteConfigure"/>
  <ComponentRef Id="Iis6ConfigExtentions"/>
  <ComponentRef Id="Iis7NewSiteConfigure"/>
  <ComponentRef Id="Iis7ExistingSiteConfigure"/>
</ComponentGroup>

<CustomAction Id="SetIisGroupToIUSRS" Property="IisGroup" Value="IIS_IUSRS" />
<CustomAction Id="SetIisGroupToWPG" Property="IisGroup" Value="IIS_WPG" />

<CustomAction Id="SetIisSiteUser" Property="IisSiteUser" Value="[APP_USER_DOMAIN]\[APP_USER_NAME]"/>

<InstallExecuteSequence>
  <Custom Action="SetIisGroupToIUSRS" After="AppSearch">IISMAJORVERSION>="#7"</Custom>
  <Custom Action="SetIisGroupToWPG" After="AppSearch">IISMAJORVERSION="#6"</Custom>
  <Custom Action="SetIisSiteUser" Before="InstallInitialize">1</Custom>
</InstallExecuteSequence> 
like image 133
Sasha Avatar answered Oct 05 '22 04:10

Sasha