How to get MSI version?

.net, c#, visual-studio-2010

Solution

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

Problem

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

Original source