2012-03-23 75 views
2

我想使用Wix在以下现有IIS结构下创建虚拟目录foo。如何使用wix在IIS中的文件夹下创建虚拟目录

//默认网站/ mywebapp /编辑

在上面的代码中,“mywebapp”是一个web applicatoin和编辑器是内部的非虚拟文件夹。我的新虚拟目录'foo'需要在非虚拟文件夹'编辑器'内创建。

我正在使用IIS 7和Wix 3.5。

以上可以使用标签完成或我需要写一个自定义操作来做到这一点?

在此先感谢

回答

0

最后我找到了一个简单的解决方案。知道我们可以使用webvirtualdir元素的别名属性的相对路径。因此,创建虚拟文件夹foo的我做了以下

  1. 使用的网站元素简称默认网站

    <iis:WebSite Id="My.Site" Description="Default Website"> 
        <iis:WebAddress Id="My.Web.Address" Port="12300"/> 
    </iis:WebSite> 
    
  2. 添加webvirtualdir元素设置为mywebapp /编辑/ foo的别名(web应用程序/子文件夹/ virtualdir )

    <Directory Id="TARGETDIR" Name="SourceDir"> 
    <Directory Id="ProgramFilesFolder"> 
        <Directory Id="INSTALLLOCATION" Name="IISDemo"> 
         <Component Id="IIS.Component" Guid="{6FAD9EC7-D2B0-4471-A657-C8AF5F6F707F}" KeyPath="yes"> 
         <iis:WebVirtualDir Id="My.VirtualDir" Alias="mywebapp/editor/foo" Directory="INSTALLLOCATION" WebSite="My.Site">    
         </iis:WebVirtualDir> 
         </Component> 
        </Directory> 
        </Directory> 
    </Directory> 
    

万万没有想到的解决方案就是这么简单。但与此同时,我已经使用system.directoryservices编写了一个自定义操作来实现相同。但是这个更简单和整洁。可能对面临相同情况的人有用。谢谢

0

这是一个很好的问题。

我没有直接的经验,但是......当遇到类似的挑战时 - 使用WiX将ISAPI作为IIS扩展安装到特定的虚拟目录中 - 我采取了使用Javascript实现的自定义操作,情况下,VBScript。我发现WiX有一些我需要的东西,但是找到正确的信息很困难,并且并非所有IIS管理功能都通过WiX公开。另外,不是所有IIS Admin的东西都暴露给Javascript,不管你信不信。在一种情况下,WMI接口需要VBArray。 !

此外,在自定义操作中,而不是单纯依赖IIS WMI(编程)接口,代码有时会调用APPCMD.exe来完成实际工作。如果你预先要求IIS7,那么你会有这个。使用appcmd创建vdir或应用程序非常简单(appcmd add appappcmd add vdir)。对我而言,最困难的部分是围绕它包装必要的支持Javascript和WiX代码。这是我做到的。

在主product.wxs文件:

<InstallExecuteSequence> 
    ... 
    <!-- configure extension if we need it --> 
    <Custom Action="CA.AddExtension" After="InstallFiles">NOT Installed AND &amp;F.Binary = 3</Custom> 
    ... 
</InstallExecuteSequence> 

,然后有一个单独的文件customactions.wxs:

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> 
    <Fragment> 
    <Binary Id="B.JavaScript" SourceFile="CustomActions.js" /> 
    <Binary Id="B.VBScript" SourceFile="MoreCustomActions.vbs" /> 

    <CustomAction Id="CA.EnumerateWebSites" 
        BinaryKey="B.JavaScript" 
        JScriptCall="EnumerateWebSites_CA" 
        Execute="immediate" 
        Return="check" /> 

    <CustomAction Id="CA.AddExtension" 
        BinaryKey="B.VBScript" 
        VBScriptCall="AddExtension_CA" 
        Execute="immediate" 
        Return="check" /> 

    .... 

然后是JavaScript的是这样的:

function RunAppCmd(command, deleteOutput) { 
    deleteOutput = deleteOutput || false; 
    LogMessage("RunAppCmd("+command+") ENTER"); 
    var shell = new ActiveXObject("WScript.Shell"); 
    var fso = new ActiveXObject("Scripting.FileSystemObject"); 
    var tmpdir = fso.GetSpecialFolder(SpecialFolders.TemporaryFolder); 
    var tmpFileName = fso.BuildPath(tmpdir, fso.GetTempName()); 
    var windir = fso.GetSpecialFolder(SpecialFolders.WindowsFolder); 
    var appcmd = fso.BuildPath(windir,"system32\\inetsrv\\appcmd.exe") + " " + command; 

    LogMessage("shell.Run("+appcmd+")"); 

    // use cmd.exe to redirect the output 
    var rc = shell.Run("%comspec% /c " + appcmd + "> " + tmpFileName, WindowStyle.Hidden, true); 
    LogMessage("shell.Run rc = " + rc); 

    if (deleteOutput) { 
     fso.DeleteFile(tmpFileName); 
    } 
    return { 
     rc : rc, 
     outputfile : (deleteOutput) ? null : tmpFileName 
    }; 
} 



// GetWebSites_Appcmd() 
// 
// Gets website info using Appcmd.exe, only on IIS7+ . 
// 
// This fn always returns site state info with each record. 
// 
function GetWebSites_Appcmd() { 
    var ParseOneLine = function(oneLine) { 
     // split the string: capture quoted strings, or a string surrounded 
     // by parens, or lastly, tokens separated by spaces, 
     var tokens = oneLine.match(/"[^"]+"|\(.+\)|[^ ]+/g); 

     // split the 3rd string: it is a set of properties separated by colons 
     var props = tokens[2].slice(1,-1); 
     var t2 = props.match(/\w+:.+?(?=,\w+:|$)/g); 
     var bindingsString = t2[1]; 
     //say(bindingsString); 
     var ix1 = bindingsString.indexOf(':'); 
     var t3 = bindingsString.substring(ix1+1).split(','); 

     var bindings = {}; 
     for (var i=0; i<t3.length; i++) { 
      var split = t3[i].split('/'); 
      var obj = {}; 
      if (split[0] == "net.tcp") { 
       var p2 = split[1].split(':'); 
       obj.port = p2[0]; 
      } 
      else if (split[0] == "net.pipe") { 
       var p3 = split[1].split(':'); 
       obj.other = p3[0]; 
      } 
      else if (split[0] == "http") { 
       var p4 = split[1].split(':'); 
       obj.ip = p4[0]; 
       if (p4[1]) { 
        obj.port = p4[1]; 
       } 
       obj.hostname = ""; 
      } 
      else { 
       var p5 = split[1].split(':'); 
       obj.hostname = p5[0]; 
       if (p5[1]) { 
        obj.port = p5[1]; 
       } 
      } 
      bindings[split[0]] = obj; 
     } 

     // return the object describing the website 
     return { 
      id   : t2[0].split(':')[1], 
      name  : "W3SVC/" + t2[0].split(':')[1], 
      description : tokens[1].slice(1,-1), 
      bindings : bindings, 
      state  : t2[2].split(':')[1] // started or not 
     }; 
    }; 

    LogMessage("GetWebSites_Appcmd() ENTER"); 

    var r = RunAppCmd("list sites"); 
    if (r.rc !== 0) { 
     // 0x80004005 == E_FAIL 
     throw new Exception("ApplicationException", "exec appcmd.exe returned nonzero rc ("+r.rc+")", 0x80004005); 
    } 

    var fso = new ActiveXObject("Scripting.FileSystemObject"); 
    var textStream = fso.OpenTextFile(r.outputfile, OpenMode.ForReading); 
    var sites = []; 

    // Read from the file and parse the results. 
    while (!textStream.AtEndOfStream) { 
     var oneLine = textStream.ReadLine(); 
     var line = ParseOneLine(oneLine); 
     LogMessage(" site: " + line.name); 
     sites.push(line); 
    } 
    textStream.Close(); 
    fso.DeleteFile(r.outputfile); 

    LogMessage("GetWebSites_Appcmd() EXIT"); 

    return sites; 
} 

也许你会觉得这很有用。

+0

谢谢你的答案cheeso。找到一个简单的解决方案,请检查答案... – vinoth 2012-04-15 02:14:30

相关问题