I want to use a single app.config by 3 different projects.
How to access the configurations?
ConfigurationManager.AppSettings["config1"]
Let's say you have this folder structure:
Do this:
For each project in Solution Explorer:
Add
> Existing Item
Select Add as link
from the drop down box next to the Add
button.
Edited to add:
You correctly state that the above method only shared the file up to build-time. To use a shared file at run-time, see the answers to this question.
The common config file
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="appSettings" type="System.Configuration.AppSettingsSection, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> </configSections> <appSettings> <add key="key1" value="value1"/> </appSettings> </configuration>
To access mapped config file
ConfigurationFileMap fileMap = new ConfigurationFileMap(file); //Path to your config file Configuration configuration = ConfigurationManager.OpenMappedMachineConfiguration(fileMap); string value = configuration.AppSettings.Settings["key1"].Value;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With