我想以与 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"]);
}
应用程序配置
<?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级)配置继承?
最佳答案
您可以使用 Slowcheetah 来实现这一点。
http://visualstudiogallery.msdn.microsoft.com/69023d00-a4f9-4a34-a6cd-7e854ba318b5
关于c# - 堆叠app.config文件,多层嵌套似乎不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24817568/