karthik
karthik

Reputation: 1

How to Apply an Transform mst to msi using c# code?

Am trying to develop a tool ( using windows forms ) in C# .Net. I have an MSI File and a MST ( Transform file ) already generated. I have to first read the msi file ( get as input from user using form menustrip menu item ), then read the mst file ( same as the way msi got as input). Next,create a temporary msi ( may be in temp location) by copying the inputted msi and apply the transform to that temp msi. Then, I can query the msi tables ( merged with mst) as per my requirements. am using Visual Studio 2010 Professional edition. here is the piece of code i have written to my knowledge using windows installer reference library.

      using System;
      using System.ComponentModel;
      using System.Windows.Forms;
      using WindowsInstaller;
      using System.Xml;
      using System.IO;

        //// Create an Installer instance
        Type classType = Type.GetTypeFromProgID("WindowsInstaller.Installer");
        Object installerObj = Activator.CreateInstance(classType);
        Installer installer = installerObj as Installer;
        Database database = Installer.OpenDatabase(File_MSI,MsiOpenDatabaseMode.
         msiOpenDatabaseModeTransact);
            database.ApplyTransform (File_MST, MsiTransformError.msiTransformErrorViewTransform);
            WindowsInstaller.View viewmst = null;
            string sqlquerymst = string.Format("Select * FROM _TransformView");
            viewmst = database.OpenView(sqlquerymst);
            viewmst.Execute(null);
            database.Commit();
            viewmst.Close();
            string sql = String.Format("Select Property,Value FROM Property");
            WindowsInstaller.View view = database.OpenView(sql);
            view.Execute(null);

Upvotes: 0

Views: 1611

Answers (1)

Yan Sklyarenko
Yan Sklyarenko

Reputation: 32240

Although it's not clear what problem you're facing with, I have some general recommendations for you:

  • Even if you're not using WiX toolset for building your MSI package(s), you can take advantage out of its .NET API for working with MSI packages, called DTF. You can find more information in the DTF.chm file which is installed together with the WiX toolset. For instance, take a look at the Database class and its ApplyTransform() method(s)
  • The scenario you describe sounds a bit tricky, and I suspect it can be simplified. If you apply transform to MSI package in order to read something brought by that transform, it might be much easier to grab that data on an earlier step when this transform is built and avoid querying MSI database which is not the most trivial thing to do. Of course, this refers to the case when you produce the transform yourself, and it's not third-party stuff

Hope this can help you in any way.

Upvotes: 1

Related Questions