Can a class library have an App.config file?

delete picture delete · Jan 27, 2011 · Viewed 60.3k times · Source

Here is what my solution is looking like at the moment:

enter image description here

In the Tutomentor.Branding project, I'd like to save branding information in the App.config file, like names, colors, etc.

In the Tutomentor.Data project, the App.config was created when I added an entity .edmx model file.

Is this possible? Any recommendations?

When deploying, will the output COMBINE these App.config files into a single one?

Answer

Matías Fidemraizer picture Matías Fidemraizer · Jan 27, 2011

No, class libraries can hold setting files, but their values will be defined in the application configuration (web.config, app.config...).

That's because of configuration settings overriding feature.

You'll need to declare the assemblies' configuration sections in the app.config or web.config of your application (WPF, SL, ASP.NET...) and define a value for a particular number of settings defined in the proper assembly settings.

EDIT: Add a setting file to your project and add a setting with application scope, and your assembly would have something like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="Assembly1.Settings1" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <applicationSettings>
        <Assembly1.Settings1>
            <setting name="settingA" serializeAs="String">
                <value>a value</value>
            </setting>
        </Assembly1.Settings1>
    </applicationSettings>
</configuration> 

Now you'd need to go to your application, and you need to copy-paste the section group, and section declarations, and the definition of the values for the settings. That's all.