我想由3个不同的项目使用一个app.config。
如何访问配置?
ConfigurationManager.AppSettings["config1"]
通用配置文件
<?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>
访问映射的配置文件
ConfigurationFileMap fileMap = new ConfigurationFileMap(file); //Path to your config file Configuration configuration = ConfigurationManager.OpenMappedMachineConfiguration(fileMap); string value = configuration.AppSettings.Settings["key1"].Value;