WiX 从 MSI 读取 ProductName 和 ProductVersion [英] WiX Read ProductName and ProductVersion from MSI

查看:29
本文介绍了WiX 从 MSI 读取 ProductName 和 ProductVersion的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 MSI 文件,我需要从中读取 ProductName 和 ProductVersion 信息.这不是SummaryInfo 数据.

I have an MSI file from which I need to read the ProductName and ProductVersion info. This is not the SummaryInfo data.

我正在使用 Microsoft.Deployment.WindowsInstaller 并具有以下代码:

I am using Microsoft.Deployment.WindowsInstaller and have the following code:

using (var database = new Database(msi, DatabaseOpenMode.ReadOnly))
{
  using (var view = database.OpenView(database.Tables["Property"].SqlSelectString))
    {
        view.Execute();
        foreach (var rec in view)
        {
            using (rec)
            {
                Console.WriteLine("{0} = {1}", rec.GetString("Property"), rec.GetString("Value"));
            }
        }
    }
}

这在枚举所有属性/值对方面做得很好,但我只需要ProductNameProductVersion添加到<代码>元组<字符串,字符串>.我如何才能从 MSI 中读取这两个值?

This does a fine job of enumerating all the Property/Value pairs, but I just need ProductName and ProductVersion to add to a Tuple<string, string>. How can I read just these two values from the MSI?

更新

我已经走到这一步了,它有效,但可能有一个更简洁/更有效的解决方案:

I got this far, and it works, but there is probably a more succint/efficient solution:

public static IEnumerable<Tuple<string, string>> GetVersionInfo()
{
    // Enumerate MSI files in C:\SetupFiles (or wherever)
    var setupFilesDir = ConfigurationManager.AppSettings["setupFilesDir"] ?? string.Empty;
    var di = new DirectoryInfo(setupFilesDir);
    var msiFiles = from msi in di.GetFiles("*.msi", SearchOption.AllDirectories)
        select msi.FullName;

    var tuples = new List<Tuple<string, string>>();

    foreach (var msi in msiFiles)
    {
        using (var db = new Database(msi, DatabaseOpenMode.ReadOnly))
        {
            var productVersion = (string)db.ExecuteScalar("SELECT `Value` FROM `Property` WHERE `Property` = 'ProductVersion'");
            var productName = (string)db.ExecuteScalar("SELECT `Value` FROM `Property` WHERE `Property` = 'ProductName'");

            tuples.Add(new Tuple<string, string>(productName, productVersion));
        }
    }

    return tuples;
}

推荐答案

我已经到了这一步,并且有效,但可能有一个更简洁/更有效的解决方案:

I got this far, and it works, but there is probably a more succint/efficient solution:

    public static IEnumerable<Tuple<string, string>> GetVersionInfo()
    {
        // Enumerate MSI files in C:\SetupFiles (or wherever)
        var setupFilesDir = ConfigurationManager.AppSettings["setupFilesDir"] ?? string.Empty;
        var di = new DirectoryInfo(setupFilesDir);
        var msiFiles = from msi in di.GetFiles("*.msi", SearchOption.AllDirectories)
            select msi.FullName;

        var tuples = new List<Tuple<string, string>>();

        foreach (var msi in msiFiles)
        {
            using (var db = new Database(msi, DatabaseOpenMode.ReadOnly))
            {
                var productVersion = (string)db.ExecuteScalar("SELECT `Value` FROM `Property` WHERE `Property` = 'ProductVersion'");
                var productName = (string)db.ExecuteScalar("SELECT `Value` FROM `Property` WHERE `Property` = 'ProductName'");

                tuples.Add(new Tuple<string, string>(productName, productVersion));
            }
        }

        return tuples;
    }

这篇关于WiX 从 MSI 读取 ProductName 和 ProductVersion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆