我需要获取 msp 文件的版本。对于 msi 文件,我使用下一个代码:
public static string GetMSIVersion(string MSIPath)
{
try
{
Type type = Type.GetTypeFromProgID("WindowsInstaller.Installer");
WindowsInstaller.Installer installer = (WindowsInstaller.Installer)
Activator.CreateInstance(type);
WindowsInstaller.Database db = installer.OpenDatabase(MSIPath, 0);
WindowsInstaller.View dv = db.OpenView("SELECT `Value` FROM `Property` WHERE `Property`='ProductVersion'");
WindowsInstaller.Record record = null;
dv.Execute(record);
record = dv.Fetch();
string str = record.get_StringData(1).ToString();
return str;
}
catch (Exception ex)
{
return "";
}
}
但对于 msp 它不起作用。有任何想法吗?