c# - 堆叠app.config文件,多层嵌套似乎不起作用

标签 c# app-config

我想以与 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)

我对带有 fileconfigSource 属性的节继承进行了一些了解(请参阅: 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级)配置继承?

最佳答案

关于c# - 堆叠app.config文件,多层嵌套似乎不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24817568/

相关文章:

c# - 在 C# 中终止指定任务而不是进程

c++ - 在 MFC 应用程序中跟踪到控制台

.net - 如何在 .NET 自定义操作中使用企业库日志记录

c# - "An error occurred creating the configuration section handler for"-

c# - 如果对象为空,如何返回空字符串?

c# - 在 javascript 中使用 C# 变量

c# - 带有 F# : System. InvalidOperationException 的 Swashbuckle:'无法找到所需的服务

c# - 检查日期等于月份的第一个日期 C#

amazon-web-services - 如何在 Amazon Elastic Beanstalk (AWS EBS) 上传递自定义环境变量?

.net - WCF 配置 - 将其从 app.config 中分离出来