Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get MSI version?

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

like image 673
chobo2 Avatar asked Apr 19 '12 17:04

chobo2


2 Answers

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

like image 195
mcdon Avatar answered Nov 10 '22 03:11

mcdon


enter image description here

to register asembly on 32 bit machine

REGSVR32 MSI.DLL

to register asembly on 64 bit machine

cd \windows\syswow64 regsvr32 C:\WINDOWS\system32\msi.dll 
like image 23
Damith Avatar answered Nov 10 '22 02:11

Damith