I have some library code which is used from my application and is also used by a .NET custom action in a Visual Studio installer project. The library code in turn uses the Enterprise Library logging block to do its logging. How can I get configuration information to the Enterprise Library in the context of my custom action running inside msiexec? Is it possible to bootstrap the config mechanism in code before I make any calls to the EntLib?
Update: I've produced a hack that seems like it will work but relies on setting a non-public static field using reflection. It's a shame that EntLib is so tightly coupled to the .NET ConfigurationManager.
var factory = new LogWriterFactory( new FakeConfigSource( "foo.config" ) );
var field = typeof ( Logger ).GetField( "factory", BindingFlags.Static | BindingFlags.NonPublic );
field.SetValue( null, factory );
Logger.Write( "Test" );
Update 2: Although that hack works in a testbed, when run in the context of msiexec, the assembly loader does not find the assemblies referenced in the config file. Fuslogvw indicates that AppBase is the windows system32 directory, which makes some sense. What I don't understand is why the custom action assembly's manifest dependencies (which are in the [TargetDir] directory alongside the custom action assembly) are found, but dynamically-loaded assemblies called out in the config file are not. Can't see any way around this.
There is no way to use the standard app.config way because that app.config is the msiexec.config you would need to edit prior to executing your MSI. My recommendation would be to have your own configuration loading method which reads from a custom XML or values in the MSI.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With