【发布时间】:2012-11-29 10:51:40
【问题描述】:
我在我的项目 web.config 中定义了几个自定义配置部分,使用当前的 web.config 设置,这些部分可以毫无问题地引用。我现在正尝试将其中一些自定义配置部分连同 appSettings 条目一起提取到它们自己的 .config 文件中,因为这些值会随着环境(DEV、QA、UAT、PROD)的变化而变化。
我遇到的问题是,如果我的自定义配置部分指向同一个文件,它们每个都希望根元素是那种类型。以下是尝试的 web.config 设置的 sn-p。
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="custom1" type="Namespace.custom1, myProject"/>
<section name="custom2" type="Namespace.custom2, myProject"/>
</configSections>
<custom1 file="/Dev.config">
</custom1>
<custom2 file="/Dev.config">
</custom2>
<appSettings file="/Dev.config">
... non environment specific entries
</appSettings>
</configuration>
在我的 Dev.config 文件中,我有以下部分
<?xml version="1.0"?>
<custom1>
<customVal1 attr1="abc" attr2="xyz"/>
</custom1>
<custom2>
<diffCustomVal1 difAttr1="True" difAttr2="Jim"/>
</custom2>
<appSettings>
... environment specific entries
</appSettings>
我在网上查看过,但没有找到任何我喜欢的想法。我想知道其他人是如何解决这个问题的。我还尝试从不同的自定义配置部分创建一个单一的外部配置,将上面显示的配置放在该文件中,但随后程序无法从该配置文件中提取 appSettings 条目。
【问题讨论】:
标签: visual-studio-2010 configuration web-config