我希望以与web.config文件工作方式类似的方式堆叠app.config文件。
我真的想要进入以下层次结构
machine.config (nice and clean no extra config)
Environment config (in source control shared by everyone)
app.config/web.config (config at a non-environmental application level)
Developers hack config (overrides all the things)
我已经对file
或configSource
属性的部分继承进行了一些了解(参见:ASP.NET web.config: configSource vs. file attributes)
然而,我似乎无法找到任何方法来叠加这些超过一层的深度,例如
static void Main(string[] args)
{
Console.WriteLine("Setting1: {0}", ConfigurationManager.AppSettings["setting1"]);
Console.WriteLine("Setting2: {0}", ConfigurationManager.AppSettings["setting2"]);
Console.WriteLine("Setting3: {0}", ConfigurationManager.AppSettings["setting3"]);
}
的app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings file="tier1.config">
<add key="setting1" value="yay"/>
</appSettings>
</configuration>
tier1.config
<?xml version="1.0" encoding="utf-8" ?>
<!--appSettings file="tier2.config"--><!-- using this gives the following: Unrecognized attribute 'file'. Note that attribute names are case-sensitive. -->
<appSettings>
<add key="setting2" value="yay"/>
</appSettings>
tier2.config
<?xml version="1.0" encoding="utf-8" ?>
<appSettings>
<add key="setting3" value="yay"/>
</appSettings>
有没有办法使用文件属性或其他东西来获得多个级别(超过2个)的配置继承?
答案 0 :(得分:2)