views:

273

answers:

2

So I cant find a definitive answer to the Question. How do you load the app.config file into a DLL.

I understand that generally the App.config info should be put into the executable app.config. However i am building an add-in and have to executable available.

I would like to use the namespace.dll.config file to store my variables, but i need a way of loading it into the system.

Do you need to build out some code to load this file in?
Can you use the configurationManager namespace to make this happen easily?

+1  A: 

This example will load any *.config file from your bin directory as a new configuration object.

Alternatively, .NET Settings will automatically compile the default into the assembly.

public Configuration DllConfiguration( string filename )
{
    var map = new ExeConfigurationFileMap {
         ExeConfigFilename = Path.Combine( AppDomain.CurrentDomain.BaseDirectory, filename )
    };

    return ConfigurationManager.OpenMappedExeConfiguration( map, ConfigurationUserLevel.None );
}
Lachlan Roche
+1  A: 

The way this is done is that you should supply your assembly.dll.config to consumers of your assembly. They should then incorporate those entries into their application's config file.

Your assembly will then be able to access those values through normal means.

John Saunders