Web配置转换为自定义部分

Web配置转换为自定义部分

本文介绍了Web配置转换为自定义部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的MVC 5应用程序中有许多用于不同环境的不同Web.config-例如测试/生产

I have numerous different Web.configs in my MVC 5 Application for different environments - e.g. Test/Prod

我已经进行了Web转换,以更改不同环境的值.因此,例如,我的web.config文件中具有以下应用程序设置:

I have web transforms in place to change values for the different environments. So for example I have the following app setting in my web.config file:

<appSettings>
<add key="DevDisplayPanel" value="true" />
</appSettings>

然后使用Web转换在我的Web.Test.config和Web.Prod.config中更改值,如下所示:

Then in my Web.Test.config and Web.Prod.config using a web transform to change the value as below:

<appSettings>
<add key="DevDisplayPanel"
     xdt:Transform="Replace"
     xdt:Locator="Match(key)"
     value="false" />
<appSettings>

但是,在Web.config中,我也有自己的自定义部分,该部分位于<appSettings>部分之外,如下所示:

However in my Web.config I also have my own custom section which is outside the <appSettings> section and is as below:

  <myCustomSection>
    <serverList>
      <add zone="Zone1" url="https://dev-myurl1.com"/>
      <add zone="Zone2" url="https://dev-myurl2.com"/>
      <add zone="Zone2" url="https://dev-myurl3.com"/>
    </serverList>
  </myCustomSection>

我的问题是-是否可以进行网络转换,以便Test和Prod如下所示:

My question is - is it possible to have a web transform so that for Test and Prod would look as below:

测试:

  <myCustomSection>
    <serverList>
      <add zone="Zone1" url="https://test-myurl1.com"/>
      <add zone="Zone2" url="https://test-myurl2.com"/>
      <add zone="Zone2" url="https://test-myurl3.com"/>
    </serverList>
  </myCustomSection>

产品:

  <myCustomSection>
    <serverList>
      <add zone="Zone1" url="https://prod-myurl1.com"/>
      <add zone="Zone2" url="https://prod-myurl2.com"/>
      <add zone="Zone2" url="https://prod-myurl3.com"/>
    </serverList>
  </myCustomSection>

推荐答案

您可以尝试替换<serverList>标记的内容.

You can try replacing the contents of the <serverList> tag.

测试:

<myCustomSection>
    <serverList xdt:Transform="Replace">
        <add zone="Zone1" url="https://test-myurl1.com"/>
        <add zone="Zone2" url="https://test-myurl2.com"/>
        <add zone="Zone2" url="https://test-myurl3.com"/>
    </serverList>
</myCustomSection>

产品:

<myCustomSection>
    <serverList xdt:Transform="Replace">
        <add zone="Zone1" url="https://prod-myurl1.com"/>
        <add zone="Zone2" url="https://prod-myurl2.com"/>
        <add zone="Zone2" url="https://prod-myurl3.com"/>
    </serverList>
</myCustomSection>

这篇关于Web配置转换为自定义部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 03:46