Search code examples
c#visual-studio-2010dllconfigproperties.settings

How can I consolidate my dll project settings into my main exe.config file in Visual Studio 2010 for a C# application?


I can't give specifics about the application I'm working on, but the idea should be basic, I just can't find anything on this issue specifically.

I have two C# projects in a solution in Visual Studio 2010. One is an executable and it references the other, which is a DLL.

The DLL has specific configuration settings that I want to modify externally and so does the executable, but building the application results in only one config file without any of the values of the DLL file's configuration.

It seems that the configuration file for the DLL becomes internal and cannot be changed, but I need to be able to change these values.

An older, similar application I have access to has a configuration file that accesses them both but I don't know how to get this to work in 2010. It says the configuration manager failed to load if I try editing the config file like this:

    <EXEFILE.Properties.Settings>
        <setting name="Delimiter" serializeAs="String">
            <value>","</value>
        </setting>
    </EXEFILE.Properties.Settings>
    <DLLFILE.Properties.Settings>
        <setting name="logDirectory" serializeAs="String"><value>C:\logs</value></setting>
    </DLLFILE.Properties.Settings>

Solution

  • ExeConfigurationFileMap map = new ExeConfigurationFileMap();
    map.ExeConfigFilename = "..\\mydll.config";
    Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map,  ConfigurationUserLevel.None);
    AppSettingsSection section = (AppSettingsSection)config.GetSection("appSettings");