windows 使用 WiX 创建 IIS 虚拟目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/624918/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using WiX to create an IIS virtual directory
提问by user75467
I'd ask this on the WiX mailing list, but it seems to be down.
我会在 WiX 邮件列表上问这个问题,但它似乎已关闭。
I have an application which is both a desktop app and a web app which runs locally. I've created a couple of basic WiX installers, but haven't yet used the IIS extension to create a virtual directory under IIS. I haven't been able to find a simple example of how to do this. All I need to do is create the virtual directory, set its port, and point it at a real directory which I'm creating with the rest of the installer.
我有一个应用程序,它既是桌面应用程序,又是本地运行的 Web 应用程序。我已经创建了几个基本的 WiX 安装程序,但还没有使用 IIS 扩展在 IIS 下创建虚拟目录。我一直没能找到一个简单的例子来说明如何做到这一点。我需要做的就是创建虚拟目录,设置它的端口,然后将它指向我正在与安装程序的其余部分一起创建的真实目录。
A bonus would be enabling IIS on the machine if it's not already enabled, but I'm guessing that's not possible, and isn't a dealbreaker for me anyway.
如果尚未启用 IIS,则在机器上启用 IIS 是一个奖励,但我猜这是不可能的,无论如何对我来说都不是交易破坏者。
If it matters, this installer will only be run on Vista machines.
如果重要的话,这个安装程序只能在 Vista 机器上运行。
回答by Eric Smith
Since the article mentioned by David seems lost, here is an example. This also creates an application in the virtual directory.
由于大卫提到的文章似乎丢失了,这里举个例子。这也会在虚拟目录中创建一个应用程序。
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:iis="http://schemas.microsoft.com/wix/IIsExtension">
<Product Id="6f2b2358-YOUR-GUID-HERE-aa394e0a73a2" Name="WixProject" Language="1033" Version="1.0.0.0" Manufacturer="WixProject" UpgradeCode="225aa7b2-YOUR-GUID-HERE-110ef084dd72">
<Package InstallerVersion="200" Compressed="yes" />
<Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />
<!-- Reference existing site at port 8080 -->
<iis:WebSite Id="My.Site" Description="My Site">
<iis:WebAddress Id="My.Web.Address" Port="8080"/>
</iis:WebSite>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLLOCATION" Name="WixProject">
<Component Id="IIS.Component" Guid="{6FAD9EC7-YOUR-GUID-HERE-C8AF5F6F707F}" KeyPath="yes">
<iis:WebVirtualDir Id="My.VirtualDir" Alias="foo" Directory="INSTALLLOCATION" WebSite="My.Site">
<iis:WebApplication Id="My.Application1" Name="Web Application 1"/>
</iis:WebVirtualDir>
</Component>
</Directory>
</Directory>
</Directory>
<Feature Id="ProductFeature" Title="WixProject" Level="1">
<ComponentRef Id="IIS.Component" />
</Feature>
</Product>
</Wix>
回答by David Pokluda
Use iis:WebVirtualDir
and iis:WebApplication
from http://schemas.microsoft.com/wix/IIsExtension
namespace.
使用iis:WebVirtualDir
和iis:WebApplication
来自http://schemas.microsoft.com/wix/IIsExtension
命名空间。
I had a similar question earlier and I found the following article quite useful: Wix 3.0 Creating IIS Virtual Directory
我之前有一个类似的问题,我发现以下文章非常有用:Wix 3.0 Creating IIS Virtual Directory
回答by Aardvark
Digging in the Google cache (which I think is now been purged by Google) I think the following is the code to the missing blog entry David Pokluda included in his answer. I had to do some reformatting to get this into SO, sorry if it's ugly.
挖掘 Google 缓存(我认为现在已被 Google 清除)我认为以下是 David Pokluda 的答案中包含的丢失博客条目的代码。我必须进行一些重新格式化才能将其变为 SO,如果它很丑,我很抱歉。
<?xml version="1.0" encoding="UTF-8"?>
<!--
IMPORTANT
1. need to add the schema iis.xsd to the property window
2. add the following iis namespace
3. add the Visual Studio reference WixIIsExtenion
-->
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:iis="http://schemas.microsoft.com/wix/IIsExtension">
<Product Id="7b523f47-YOUR-GUID-HERE-fea6be516471"
Name="Vince Wix 3 Web Service"
Language="1033"
Version="1.0.0.0"
Manufacturer="Vince LLC"
UpgradeCode="0a8c10df-YOUR-GUID-HERE-50b9ecdb0a41">
<Package InstallerVersion="200" Compressed="yes" />
<Media Id="1" Cabinet="WebAppWixProject.cab" EmbedCab="yes" />
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="WebApplicationFolder" Name="MyWebApp">
<Component Id="ProductComponent" Guid="80b0ee2a-YOUR-GUID-HERE-33a23eb0588e">
<File Id="Default.aspx" Name="Default.aspx" Source="..\MyWebApp\Default.aspx" DiskId="1" />
<File Id="Default.aspx.cs" Name="Default.aspx.cs" Source="..\MyWebApp\Default.aspx.cs" DiskId="1"/>
<iis:WebVirtualDir Id="MyWebApp" Alias="MyWebApp" Directory="WebApplicationFolder" WebSite="DefaultWebSite">
<iis:WebApplication Id="TestWebApplication" Name="Test" />
</iis:WebVirtualDir>
</Component>
</Directory>
</Directory>
</Directory>
<!--
IMPORTANT
Add a virtual directory to an existing web site
If put it inside the Component, a new Web Site will be created and uninstall will remove it
-->
<iis:WebSite Id='DefaultWebSite' Description='Default Web Site' Directory='WebApplicationFolder'>
<iis:WebAddress Id="AllUnassigned" Port="80" />
</iis:WebSite>
<Feature Id="ProductFeature" Title="Vince Wix 3 Web Service" Level="1">
<ComponentRef Id="ProductComponent" />
</Feature>
</Product>
</Wix>
<!--
IMPORTANT
To get rid of light.exe location error, do the following on the Linker Tab:
Set culture to: en-US
Supress Schema Validation in the Advanced Button
-->
回答by tarn
I'm not familiar with WiX, but both IIS 6 and 7 can be managed using WMI (Windows Management Instrumentation) objects. I've used both PowerShell and C# to create websites, virtual directories, permissions etc on IIS. You should be able to get your hands on these objects from most scripting environments.
我不熟悉 WiX,但 IIS 6 和 7 都可以使用 WMI(Windows 管理规范)对象进行管理。我已经使用 PowerShell 和 C# 在 IIS 上创建网站、虚拟目录、权限等。您应该能够从大多数脚本环境中获得这些对象。
回答by bjdodo
The above snippets use the iis:WebAddress in an improper way. You need to add IP="*" if you want this to work with all websites that match the name and the port. The above example fails during the install if there is an ip address assigned to the website in IIS (wix CA will not find it in general)
上面的代码片段以不正确的方式使用了 iis:WebAddress。如果您希望它适用于与名称和端口匹配的所有网站,则需要添加 IP="*"。如果在IIS中有分配给网站的ip地址,上面的例子在安装过程中会失败(wix CA一般不会找到它)
Rant: wix is terrible for many reasons, in my opinion and this is a good example. If the attribute is missing it will only work for websites with the default IP - how unintuitive is this. Wix should at least emit a waring for a missing IP element. Furthermore the default IP (localhost) is represented as * in IIS metabase, at the same time in the wix file * means all websites (not only *). So it is really confusing and not intuitive at all.
Rant:在我看来,wix 很糟糕的原因有很多,这是一个很好的例子。如果缺少该属性,它将仅适用于具有默认 IP 的网站 - 这是多么不直观。Wix 至少应该对丢失的 IP 元素发出警告。此外,默认 IP (localhost) 在 IIS 元数据库中表示为 *,同时在 wix 文件中 * 表示所有网站(不仅是 *)。所以它真的很混乱,一点也不直观。