如何获得MSI版本?

cho*_*bo2 5 .net c# visual-studio-2010

我试图使用教程中的代码从MSI获取版本而不安装它,但当我尝试将"msi.dll"添加到Visual Studio 2010作为参考时,我收到此错误.

无法加载文件或程序集"msi.dll"或其依赖项之一.该模块应该包含一个程序集清单.

此文件可能不是托管程序集

mcd*_*don 17

使用Wix项目的部署工具基础(DTF)中的"Microsoft.Deployment.WindowsInstaller.dll".DTF为msi.dll的大部分提供了托管包装器.Wix还提供了有用的文档.

在这里使用DTF是我如何在C#中访问msi的版本号

using Microsoft.Deployment.WindowsInstaller;

namespace Msi.Tables
{
    public class PropertyTable
    {
        public static string Get(string msi, string name)
        {
            using (Database db = new Database(msi))
            {
                return db.ExecuteScalar("SELECT `Value` FROM `Property` WHERE `Property` = '{0}'", name) as string;
            }
        }
        public static void Set(string msi, string name, string value)
        {
            using (Database db = new Database(msi, DatabaseOpenMode.Direct))
            {
                db.Execute("UPDATE `Property` SET `Value` = '{0}' WHERE `Property` = '{1}'", value, name);
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

然后从我的申请

string msiVersion = PropertyTable.Get("MyInstall.msi", "ProductVersion");
Run Code Online (Sandbox Code Playgroud)

您可以使用Orca查看msi表.MSDN提供了有关属性表的文档.MSDN中也提供了有关Windows Installer的SQL语法的详细信息