从Msi,如何获取每个功能中包含的文件列表?

时间:2012-07-12 06:38:30

标签: powershell wix windows-installer powershell-v2.0

我们使用wix创建了Msi。每个Msi将具有1或2或3个功能,如Appserver功能,Web服务器功能和数据库服务器功能。

现在我被要求获取每个功能中显示的配置文件列表。

很难通过wxs文件找到与每个功能相关联的web.config文件列表。

是否可以找到与具有特定搜索模式的功能相关联的文件列表?

对于前。找到Appserver功能中打包的所有web.config文件。

有没有简单的方法(查询或其他一些自动脚本,如powershell)来获取列表?

2 个答案:

答案 0 :(得分:1)

Wix附带了一个称为DTF的.NET SDK(“部署工具基础”)。它包装了窗口msi.dll等等。您可以在Wix Toolset安装目录的SDK子目录中找到这些.NET Microsoft.Deployment.*.dll程序集。该文档位于doc子目录中的dtf.chmdtfapi.chm

如文档中所示,您可以使用此SDK编写使用SQL查询msi数据库的代码。您会对FeatureFeatureComponentsFile表感兴趣。

如果您之前没有探索过MSI的内部,可以使用orca打开它来感受它。

答案 1 :(得分:0)

您可以对Get-MsiProperties function described in this PowerShell article稍作修改。

请阅读原始文章并创建指定的comObject.types.ps1xml文件。

function global:Get-MsiFeatures {
    PARAM (
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true,HelpMessage="MSI Database Filename",ValueFromPipeline=$true)]
        [Alias("Filename","Path","Database","Msi")]
        $msiDbName
    )

    # A quick check to see if the file exist
    if(!(Test-Path $msiDbName)){
        throw "Could not find " + $msiDbName
    }

    # Create an empty hashtable to store properties in
    $msiFeatures = @{}

    # Creating WI object and load MSI database
    $wiObject = New-Object -com WindowsInstaller.Installer
    $wiDatabase = $wiObject.InvokeMethod("OpenDatabase", (Resolve-Path $msiDbName).Path, 0)

    # Open the Property-view
    $view = $wiDatabase.InvokeMethod("OpenView", "SELECT * FROM Feature")
    $view.InvokeMethod("Execute")

    # Loop thru the table
    $r = $view.InvokeMethod("Fetch")
    while($r -ne $null) {
        # Add property and value to hash table
        $msiFeatures[$r.InvokeParamProperty("StringData",1)] = $r.InvokeParamProperty("StringData",2)

        # Fetch the next row
        $r = $view.InvokeMethod("Fetch")
    }

    $view.InvokeMethod("Close")

    # Return the hash table
    return $msiFeatures
}
相关问题