在WiX中,如何按名称选择IIS网站?

Dan*_*Dan 12 iis iis-7 iis-6 wix wix3

我想要做的是向安装程序用户显示其服务器上的网站列表,并允许他们选择一个(使用此处描述的方法:http://www.cmcrossroads.com/content/view/13160/120/,现在似乎已经破了,请看这里的核心代码).然后,安装程序将在所选网站中创建虚拟目录.

但是,我的搜索似乎表明,在WiX中指定网站的唯一方法是通过IP,端口和标头.要求这些不是非常用户友好,所以我留下了编写第二个自定义操作以从网站名称获取这些详细信息的想法.

有没有更好的办法?

BTW这需要在IIS6和IIS7中工作,以防影响答案.

Dan*_*Dan 10

好的,有可能(在IIS6或IIS7中兼容Metabase),感谢这篇帖子到邮件列表,解释了iis:Website元素工作的一些奇怪的方式.有用的部分是:

Using a fragment like this and test with v3.0.5120.0:*

  <iis:WebSite Id="WebSite" Description="Default Web Site" SiteId="*">
    <iis:WebAddress Id="TestWebSite" Port="1" />
  </iis:WebSite>

The following work:

1. If WebSite/@SiteId="*" then a case sensitive match on WebSite/@Description happens.
2. If WebSite/@SiteId matches the site id than WebSite/@Description is ignored and a match on site id happens.
3. If WebSite/@SiteId has any value WebAddress/@Port is ignored (although the syntax requires it and it can't be 0).
4. If WebSite/@SiteId is missing WebAddress/@Port is used and WebSite/@Description is ignored.
5. Once a website is created and gets site id, you can rename it (therefore its site id is not the hash of its name), the WebSite/@SiteId="*" syntax will match on the WebSite/@Description.
Run Code Online (Sandbox Code Playgroud)

所以我的WiX代码最终看起来像:

<DirectoryRef Id="TARGETDIR">
  <Component Id="IisSetup" Guid="YOUR-GUID-HERE">
    <iis:WebVirtualDir Id="IisVirtualDir" Alias="[IIS_VIRTUALDIRNAME]" Directory="INSTALLLOCATION" WebSite="IisWebsite">
      <iis:WebApplication Id="IisWebApplication" Name="[IIS_VIRTUALDIRNAME]" WebAppPool="IisAppPool" Isolation="high"/>
    </iis:WebVirtualDir>
    <iis:WebAppPool Id="IisAppPool" Name="[IIS_APPPOOLNAME]" Identity="networkService"/>
  </Component>
</DirectoryRef>

<!-- Note that this entry should not be put under a component. If it is WiX
     will update the website on install and remove it on uninstall -->
<iis:WebSite Id="IisWebsite" Description="[IIS_WEBSITENAME]" SiteId="*">
  <iis:WebAddress Id="IisWebAddress" Port="80" />
</iis:WebSite>
Run Code Online (Sandbox Code Playgroud)

永远不应该使用iis:WebAddress元素,但这是项目编译所必需的.