How to properly use a config file during runtime #1846
-
|
Hi everyone, I'm trying to configure my installer in a probably unconventional way and looking for ideas on how to solve it. Maybe there are more convenient ways that I don't know of. The installer comes with multiple services, and during installation each service's files are moved to the install folder, and the service is installed with the service installer. I now want to configure which services are actually enabled and should be installed to the target system. The user has no control over it (so I'm not talking about features.) The actual configuration is done after the installers' compile time. But the installer already contains a default configuration (JSON). Now I try to achieve reading in the config during the installer runtime and enable/disable services before installing corresponding files. My idea was to either use conditions (see sample 'Contitional Installation') or feature conditions ('FeatureConditions'). I know how to handle them and read the properties. But I'm stuck with the part where I read the file and set the properties. I know I can use custom actions to read in the file on launch, but that would require the file to be already copied to the installdir. Is there any way to read the configuration from the internal components as early as possible? Bonus question: For convenient reasons, I'd like to ship my installer as a single MSI. That means I have to extract the config file and repack the MSI to replace the default config with a custom config. Are there better ideas to handle that? Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
|
After your MSI is built, you can generate your configuration file and add it to the already assembled MSI in the Binary table. |
Beta Was this translation helpful? Give feedback.
-
|
This is how you can insert the file in the Binary table: public static void InsertToBinaryTable(this string msiPath, string binaryKey, string fileToInsert)
{
// Open MSI database in Direct mode (allows modifications)
using (var db = new Database(msiPath, DatabaseOpenMode.Direct))
{
using (var view = db.OpenView("INSERT INTO `Binary` (`Name`, `Data`) VALUES (?, ?)"))
{
using (var rec = new Record(2))
{
rec.SetString(1, binaryKey);
rec.SetStream(2, fileToInsert); // stream inserts the file content
view.Execute(rec);
}
}
db.Commit();
}
} |
Beta Was this translation helpful? Give feedback.


It's
args.Session.ReadBinary(<your file id in the Binary table>)Inserting teh file in teh Binary table of the existing MSI is a separate topic and you will find the answer online. It can be even done with teh vb script.
If you are OK to distribute exe, not msi file then you may have even a simpler solution.
here is the example