我在web.config中有3个部分,它们定义了相同静态类的值:
<def_1
...
...
/>
<def_2
...
...
/>
<def_3
...
...
/>
我想在运行中选择使用哪个配置。
<configSections>
<section name="MyClass_1" type="myapp.def_1" />
<section name="MyClass_2" type="myapp.def_2" />
<section name="MyClass_3" type="myapp.def_3" />
</configSections>
我希望能够根据需要使用MyClass_1,_2或_3。每个类都有Prod,QA和Dev环境的定义,我希望能够在环境之间轻松切换。希望这不是太模糊。谁能想到一个简单的方法呢?目前我们只是编辑web.config以使用我们想要的任何类,但我不想编辑它。
此外,我想补充说,这是我可以采取的唯一方法,因为我们有许多应用程序使用它,只有一个小的修改是可以接受的,以尝试促进他们的愿望。如果它不能完成(我认为它不能)那么那就是我给他们的答案。
答案 0 :(得分:2)
您应该只有一个配置部分,但可以有3个不同的环境特定文件并配置配置文件,以便在<MyClass></MyClass>
设置中应用转换。
一个体面的.config
转换插件是SlowCheetah,请在https://marketplace.visualstudio.com/items?itemName=VisualStudioProductTeam.SlowCheetah-XMLTransforms
这是一个样本转换。
<system.serviceModel>
<bindings xdt:Transform="Replace">
<basicHttpBinding>
<binding name="myServiceReference">
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>