我有一个用于应用程序的自定义 .NET 插件,我正在尝试为插件的配置文件创建 configSections。问题是如果使用 OpenMapperExeConfiguration/OpenExeConfiguration 加载配置,我无法阅读该部分。
这是我的配置文件(MyTest.dll.config)
<configuration>
<configSections>
<section name="test" type="MyTest, Test.ConfigRead"/>
</configSections>
<test>
..Stuff here
</test>
<appSettings>
<add key="uri" value="www.cnn.com"/>
</appSettings>
</configuration>
这是我访问测试configSection的代码示例
ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = Assembly.GetExecutingAssembly().Location + "config";
Configuration applicationConfig = ConfigurationManager.OpenMappedExeConfiguration(fileMap,ConfigurationUserLevel.None);
//Using OpenExeConfiguration doesnt help either.
//Configuration applicationConfig = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);
//Accessing test section
applicationConfig.GetSection("test");
//Accessing AppSettings works fine.
AppSettingsSection appSettings = (AppSettingsSection)applicationConfig.GetSection("appSettings");
appSettings.Settings["uri"].Value;
如图所示 appsettings 值可以很好地读取。除了主应用程序的配置文件之外,是否可以在任何其他配置中包含 configSections?