R – How to configure multiple modules using .net configuration files

configurationnet

I have a few .net modules/libraries I am referencing from my main application. Each of the modules/libraries can be configured and after I build them they each have a configuration file such as MyModule1.dll.config, MyModule2.dll.config.

When I build my main application an app.config file is outputted to the output directory.

I am wondering how to configure MyModule1, MyModule2 etc. Should I include config sections for each in the app.config file or should I have a separate config file for each module where I load a config file for each one? The separate config per module is described here: http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/2710647c-6414-42c4-90b7-fd7603f55ae0/? This would mean that I would copy MyModule1.dll.config and MyModule2.dll.config to the output directory as well.

Can anyone give me some advice on what is the best practice/proper way to do this?

Edit:

From MyModule1.dll I can explicitly load MyModule1.dll.config using

Uri p = new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
Configuration config = ConfigurationManager.OpenExeConfiguration(p.LocalPath);

but if MyModule1.dll references and uses one of my common libraries MyCommonLib.dll how can I have MyCommonLib.dll be configured from the same config file MyModule1.dll.config?

Best Answer

If you are using the Properties folder system in Visual Studio, and want Visual Studio to sync them automatically, you will want to use the config-per-module approach you have described simply for productivity.

Alternatively, if you are just dealing with or entries, it may be easier from one config file. My only advice here is to go with whatever is easiest and the most natural way for whoever else is/will be working on the project.