【发布时间】:2011-09-24 13:15:36
【问题描述】:
我有两个 .config 文件,我需要一个 System.Configuration.Configuration,它是它们之间的部分合并?
我可以将文件读取为 XML 并轻松创建所需的合并,但它是一个字符串或 XDocument。但是,.net 的 System.Configuration 似乎是严格基于文件的,所以我必须将它写入我想避免的临时目录。
有没有办法做到这一点?
例如,config1.config:
<configuration>
<appSettings>
<add key="CacheTime" value="300" />
</appSettings>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="MyBehavior">
<!-- snipped -->
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
和config2.config:
<configuration>
<system.serviceModel>
<client>
<endpoint name="MyEndpoint" address="net.tcp://...."
behaviorConfiguration="MyBehavior" binding="netTcpBinding"
contract="IMyContract">
</endpoint>
</client>
</system.serviceModel>
</configuration>
生成的配置应该是这两者的联合,这样我就有了 AppSetting 和 Endpoint。现在,这个示例包含 WCF,但我不是在寻找 WCF 特定的解决方案,因为我绝对需要一个 System.Configuration.Configuration 对象。
config1 和 config2 只是示例 - 它们的实际组合是不确定的,我可能有 config1 和 config4 或 config 3 和 config4 或 config2 和 config3。
【问题讨论】:
-
嗨迈克尔。配置文件不相交?你能发布一个两者的小例子,以及你期望的结果吗?我很乐意为您提供帮助。
标签: .net configuration web-config app-config