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!
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.