I am using a single shared config across multiple applications in my solution. Each application has the following configuration in its app.config/web.config:
<section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
<enterpriseLibrary.ConfigurationSource selectedSource="File-based Configuration Source">
<add name="File-based Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common,
Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Now, if I put settings in the AppSettings element of the C:\Source\Configuration\Entlib.config file, they are not picked up by the application. Why is this?
Is there a way to achieve this behaviour (sharing configuration values across all applications)? I do not want to put them in the machine.config. I want all my configuration in the same file (C:\Source\Configuration\Entlib.config)
You have to manually read thru it. Entlib configsource only read entlib related configuration. One approach I know is to have something like this;
FileConfigurationSource config = new FileConfigurationSource(@"C:\temp\External.config");
AppSettingsSection appSettings = config.GetSection("appSettings") as AppSettingsSection;
string myKeyValue = appSettings.Settings["myKey"].Value;
Hope this helps.
Global Technologies and Solutions
appSettings is a system configuration section, not an Entlib one, and therefore is ignorant of the existence of configuration sources. In fact, we have to jump through some hoops in the config tool to get them to show up in there at all, and they always
have to be in the system configuration file for the appSettings API to find them.