开发者

How to install multiple WebAddresses conditionally?

开发者 https://www.devze.com 2023-04-12 06:02 出处:网络
I have a website that I am installing for one of our internal products, and would like to know if there is a way to set up multiple <WebAddress/> blocks to be conditionally installed along with

I have a website that I am installing for one of our internal products, and would like to know if there is a way to set up multiple <WebAddress/> blocks to be conditionally installed along with this one website?

Consider my basic website authoring below:

<Component
    Id="WebsiteComp"
    Directory="INSTALLDIR"
    Guid="{702AF20D-F9F3-45A1-B966-890855904591}"
    KeyPath="yes">

  <iis:WebAppPool
      Id="AppPool"
      Name="OurSite"
      ManagedPipelineMode="Integrated"
      ManagedRuntimeVersion="v4.0"/>

  <iis:WebSite
      Id="Website"
      Description="[WEBSITENAME]"
      Directory="INSTALLDIR">

    <iis:WebApplication
        Id="WebApp"
        Name="[WEBSITENAME]"
        WebAppPool="AppPool"/>

    <!-- if ENV = "DEV" -->
    <iis:WebAddress
      开发者_JAVA百科  Id="DevHostHeader"
        Header="dev.product.company.com"
        Port="80"/>

    <!-- if ENV = "QA" -->
    <iis:WebAddress
        Id="QaHostHeader"
        Header="qa.product.company.com"
        Port="80"/>

    <iis:WebAddress
        Id="QaHostHeader"
        Header="product.qa1.company.com"
        Port="80"/>

    <!-- if ENV = "PROD" -->
    <iis:WebAddress
        Id="ProdHostHeader"
        Header="prod.product.com"
        Port="80"/>
  </iis:WebSite>
</Component>

<Component/> is the most specific element that a condition can applied to. But in order to specify the condition there I have to duplicate all my web site auhtoring for each environment, correct?

Is there a way to author one version of the <WebAppPool/>, <WebSite/>, and <WebApplication/> and then have different versions and quantities (like QA in the above example) of <WebAddress/> inserted/chosen based on the condition of a propertie's value?

I really don't want to get into making multiple versions of the installer for a specific environment.

Thank you,

Zachary


You can approach the problem in a different way.

You can have a single WebAddress element, and the Header attribute will take the value of the property. Like this:

<iis:WebAddress Id="HostHeader" Header="[HOSTHEADER]" Port="80"/>

Now, based on the condition (production, DEV, QA) you set the property to the required value, for instance, qa.product.company.com for QA. Thus, you'll conditionally install the host header you need, and will keep a single WebAddress entry in the sources. Note, that Port attribute can accept the property values as well.


Well, I figured out how to do it without code duplication... pre-processor to the rescue!

Here's a simplified look at my "web services" directory:

ProductName.WebService.wxs
ProductName.DEV.WebAddress.wxi
ProductName.PROD.WebAddress.wx
ProductName.QA1.WebAddress.wxi

ProductName.WebService.wxs is as follows:

<Wix
    xmlns="http://schemas.microsoft.com/wix/2006/wi"
    xmlns:iis="http://schemas.microsoft.com/wix/IIsExtension">

  <Fragment>
    <iis:WebDirProperties .../>

    <?foreach EnvID in DEV;PROD;QA1 ?>
    <?define FullEnvID = "ProductName.$(var.EnvID)" ?>

      <?if     $(var.EnvID) = "DEV" ?>
        <?define CompGUID   = "{DFEAC94A-590E-4E92-9206-E574ABDDBB29}" ?>
      <?elseif $(var.EnvID) = "PROD" ?>
        <?define CompGUID   = "{FEE4FBB1-9894-48F4-8DDC-9FC83F8AD778}" ?>
      <?elseif $(var.EnvID) = "QA1" ?>
        <?define CompGUID   = "{EED17AF6-BF99-4B34-821D-6A8487292111}" ?>
      <?endif ?>

      <Component
          Id="$(var.FullEnvID).WebSvc"
          Directory="INSTALLDIR"
          Guid="$(var.CompGUID)"
          KeyPath="yes">
        <Condition><![CDATA[ENV="$(var.EnvID)"]]></Condition>

        <iis:WebAppPool
            Id="$(var.FullEnvID).WebAppPool"
            Name="[WEBSITENAME]"
            ManagedPipelineMode="Integrated"
            ManagedRuntimeVersion="v4.0"/>

        <iis:WebSite
            Id="$(var.FullEnvID).Website"
            Description="[WEBSITENAME]"
            Directory="INSTALLDIR">

          <iis:WebApplication
              Id="$(var.FullEnvID).WebApplication"
              Name="[WEBSITENAME]"
              WebAppPool="$(var.FullEnvID).WebAppPool"/>

          <?include $(var.FullEnvID).WebAddress.wxi ?>
        </iis:WebSite>
      </Component>

      <?undef CompGUID ?>
      <?undef FullEnvID ?>
    <?endforeach ?>
  </Fragment>
</Wix>
  1. <Condition><![CDATA[ENV="$(var.EnvID)"]]></Condition> determines which web site component is installed
  2. <?include $(var.FullEnvID).WebAddress.wxi ?> slips in just the <iis:WebAddress/> sections as the loop iterates.

Here's what ProductName.DEV.WebAddress.wxi looks like:

<Include
    xmlns="http://schemas.microsoft.com/wix/2006/wi"
    xmlns:iis="http://schemas.microsoft.com/wix/IIsExtension">
  <iis:WebAddress
      Id="dev.product.company.com"
      Header="dev.product.company.com"
      Port="80"/>

  <iis:WebAddress
      Id="product.dev.company.com"
      Header="product.dev.company.com"
      Port="80"/>
</Include>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号