【问题标题】:Web config transform for custom section自定义部分的 Web 配置转换
【发布时间】:2015-05-09 03:36:22
【问题描述】:

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

我有网络转换来更改不同环境的值。例如,我的 web.config 文件中有以下应用设置:

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

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

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

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

  <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>

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

测试:

  <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>

【问题讨论】:

    标签: asp.net asp.net-mvc web-config web.config-transform web-config-transform


    【解决方案1】:

    您可以尝试替换&lt;serverList&gt;标签的内容。

    测试:

    <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>
    

    【讨论】:

    • 会试一试 - 谢谢
    • 我遇到了这个问题,但我只是在一种情况下拼错了标签,而在另一种情况下使用了错误的情况。使用 SlowCheetah [visualstudiogallery.msdn.microsoft.com/…
    猜你喜欢
    • 2011-06-17
    • 1970-01-01
    • 2010-10-25
    • 2010-11-12
    • 2013-09-17
    • 2011-07-04
    • 2012-12-12
    • 2013-09-21
    相关资源
    最近更新 更多