Fenomatik
Fenomatik

Reputation: 477

Library reference missing for WindowsInstaller C# Console Application

New to C# and VS All I am trying is to get details/properties of an msi file programmatically (eg. "Comments" in the details tab when you get file properties)

I am using the following code (using someone's code of internet) , VS is complaining about missing reference for below and also suggesting not to use "using"

using WindowsInstaller;//msi.dll

ERROR

The type or namespace name 'type/namespace' could not be found (are you missing a using directive or an assembly reference?)

And also within the function it cannot resolve any reference for the following

WindowsInstaller.Installer installer = (WindowsInstaller.Installer)Activator.CreateInstance(installerType);

Here is the code:

using System.Configuration.Install;//System.Configuration.Install.dll
using WindowsInstaller;//msi.dll

static void get_msi_details(string path)
{

// Get the type of the Windows Installer object
Type installerType = Type.GetTypeFromProgID("WindowsInstaller.Installer");


// Create the Windows Installer object
WindowsInstaller.Installer installer = (WindowsInstaller.Installer)Activator.CreateInstance(installerType);


// Open the MSI database in the input file
Database database = installer.OpenDatabase(path, MsiOpenDatabaseMode.msiOpenDatabaseModeReadOnly);

// Open a view on the Property table for the version property
View view = database.OpenView("SELECT * FROM Property WHERE Property = 'Comments'");

// Execute the view query
view.Execute(null);

// Get the record from the view
Record record = view.Fetch();

// Get the version from the data
string version = record.get_StringData(2);
}

VS studio isnt offering anything in "Potential Fixes" to resolve the reference.

Upvotes: 2

Views: 500

Answers (1)

Fenomatik
Fenomatik

Reputation: 477

In Visual Studio go to References > Add Reference... > COM > Browse... > %WINDIR%\system32\msi.dll.

Upvotes: 2

Related Questions