【发布时间】:2018-10-03 13:33:53
【问题描述】:
我已经在我的解决方案中加载了默认的App.config 文件,我可以从中访问存储的变量。
XML
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="foo" value="bar"/>
</appSettings>
</configuration>
C#
Configuration configManager = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
KeyValueConfigurationCollection config = configManager.AppSettings.Settings;
string foo = config["foo"].Value;
现在我创建了另一个配置文件来存储我的解决方案的另一部分的变量,但我不知道如何使用 ConfigurationManager 以相同的方式加载它。
Configuration config2 = ConfigurationManager.OpenExeConfiguration("path/to/config.config");
【问题讨论】:
-
你尝试了会发生什么? this post 会帮忙吗?
-
为什么不使用自定义文件来设置配置?
-
您是否将配置文件的属性设置为
Build action = Content和Copy to Output Directory = Copy if newer(或其他)?
标签: c#