Web config transform for custom section

旧时模样 提交于 2019-12-06 00:26:47

问题


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

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>

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>

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>

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

Test:

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

Prod:

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

回答1:


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

Test:

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

Prod:

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


来源:https://stackoverflow.com/questions/28917289/web-config-transform-for-custom-section

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!