How to extract and run a file during installation

2019-07-29 17:50发布

I have created a Custom Action (DTF) with C#.
In that CA, I would like to extract a file from the msi (declared as Binary in wix) and run it with some arguments.
I haven't found any samples or help about that..
I have to execute a request on the msi, but I would like to have a sample. Thanks!

标签: wix wix3.5 dtf
1条回答
一纸荒年 Trace。
2楼-- · 2019-07-29 18:35

The DTF.chm has a sample how to update the Binary table. It's in "Working with MSI Databases" topic. And you can guess how to do the opposite operation. The code might look like this:

  using (var db = new Database("test.msi", DatabaseOpenMode.Direct))
  {
    using (var view = db.OpenView("SELECT `Data` FROM `Binary` WHERE `Name` = '{0}'", "testbinary"))
    {
      view.Execute();
      var rec = view.Fetch();

      var inStream = rec.GetStream("Data");
      if (inStream != null)
      {
        using (var file = File.OpenWrite("S:\\testfile.zip"))
        {
          CopyStream(inStream, file);
        }
      }
    }
  }

The code of CopyStream method can be taken from this answer of omnipresent Jon Skeet. Note that if you should do this from CA, you will reference the database object like session.Database, instead of creating it.

查看更多
登录 后发表回答