Anh Nguyen
Anh Nguyen

Reputation: 313

How to create transform for .msi file using c#

I'm trying to create a transform for .msi file in C#. Here is my code:

 public static void CreateTransforms(string original_MSI, string backup_MSI, string MSTpath, string query)
    {
        File.Copy(original_MSI, backup_MSI, true);
        using (var origDatabase = new Microsoft.Deployment.WindowsInstaller.Database(original_MSI, DatabaseOpenMode.ReadOnly))
        {
            using (var database = new Microsoft.Deployment.WindowsInstaller.Database(backup_MSI, DatabaseOpenMode.Direct))
            {
                //database.Execute("Update `Property` Set `Property`.`Value` = 'Test' WHERE `Property`.`Property` = 'ProductName'");
                database.Execute(query);
                database.GenerateTransform(origDatabase, MSTpath);
                database.CreateTransformSummaryInfo(origDatabase, MSTpath, TransformErrors.None, TransformValidations.None);
            }
        }
    }

I got the following error : "This installation package could not be opened. Contact the application vendor to verify that this is a valid Windows Installer package." in the step create transform summary info. I used "Microsoft.Deployment.WindowsInstaller.dll" library. Any help would be great.

Upvotes: 0

Views: 1148

Answers (2)

user4781413
user4781413

Reputation: 9

when CreateTransforms start, it open database and it does not close it ... you must commit and close the database before apply a new transform!

                database.GenerateTransform(origDatabase, TRANSFORM);
                database.CreateTransformSummaryInfo(origDatabase, TRANSFORM, TransformErrors.None, TransformValidations.None);
                database.Commit();
                database.Close();

Upvotes: 0

Christopher Painter
Christopher Painter

Reputation: 55601

A quick read of this static method looked correct so I created a console app out of it. It works fine for me on my machine. I would look at your calling method and make sure the data being passed is correct. I get really nervous any time I have a method that takes 4 strings as arguments as that leaves a lot to desire in terms of type safety.

Upvotes: 1

Related Questions