2012-03-23 70 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

相關問題