Web config transform for custom section
Asked Answered
G

1

10

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>
Galang answered 7/3, 2015 at 16:45 Comment(0)
A
19

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>
Assignment answered 7/3, 2015 at 16:51 Comment(1)
I had this problem, but I had simply misspelled a tag in one case and used the wrong case in another. Using SlowCheetah [visualstudiogallery.msdn.microsoft.com/…Reverend

© 2022 - 2024 — McMap. All rights reserved.