我试图用这个code本教程的的入门版微星没有安装它 的,但是当我尝试将加上MSI.DLL到Visual Studio 2010作为参考,我得到这个错误
无法加载文件或程序集MSI.DLL或它的某一个依赖。 该模块应包含一个程序集清单。
该文件可能不是托管程序集
解决方案从维克斯项目的部署工具基金会(DTF)使用Microsoft.Deployment.WindowsInstaller.dll。 DTF提供托管的包装大部分MSI.DLL的。维克斯还提供了有用的文档。
使用DTF这是我如何访问在C#中的MSI的版本号
使用Microsoft.Deployment.WindowsInstaller;
命名空间Msi.Tables
{
公共类PropertyTable
{
公共静态字符串获取(字符串微星,字符串名称)
{
使用(数据库DB =新的数据库(MSI))
{
返回db.ExecuteScalar(选择`Value`从`Property` WHERE`Property` ='{0}',名称)的字符串;
}
}
公共静态无效设置(字符串微星,字符串名称,字符串值)
{
使用(数据库DB =新的数据库(MSI,DatabaseOpenMode.Direct))
{
db.Execute(更新`Property` SET`Value` ='{0}'这里'Property` ='{1}',值,名称);
}
}
}
}
然后,从我的应用程序
字符串msiVersion = PropertyTable.Get(MyInstall.msi,的ProductVersion);
您可以使用Orca查看MSI表。 MSDN提供了有关属性表文档。 Windows安装在 SQL语法细节也可以在MSDN
I am trying to use this code from the tutorial Getting version from MSI without installing it, but when I try to add the "msi.dll" to Visual Studio 2010 as a reference I get this error.
Could not load file or assembly 'msi.dll' or one of its dependencies. The module was expected to contain an assembly manifest.
This file may not be a managed assembly
解决方案
Use "Microsoft.Deployment.WindowsInstaller.dll" from the Wix project's Deployment Tools Foundation (DTF). DTF provides a managed wrapper for much of msi.dll. Wix also provides helpful documentation.
Using DTF here is how I accessed the version number of an msi in C#
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);
}
}
}
}
Then from my application
string msiVersion = PropertyTable.Get("MyInstall.msi", "ProductVersion");
You can use Orca to view the msi tables. MSDN provides documentation on the Property Table. The details on SQL syntax for Windows Installer is also available in MSDN