Search code examples
xmlweb-config-transform

Web.Config Transform not changing any values


I'm trying to set up a web.config transform to modify some values. I am using this example given by Octopus Deploy:

http://docs.octopusdeploy.com/display/OD/Configuration+files

ultra-slimmed down version of web.config:

<?xml version="1.0" ?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  <system.web>
    <compilation debug="true" targetFramework="4.0">
    </compilation>
  </system.web>
</configuration>

the transform:

<?xml version="1.0" ?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
  </system.web>
</configuration>

the output:

<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  <system.web>
    <compilation debug="true" targetFramework="4.0">
    </compilation>
  </system.web>
</configuration>

I'm using this tool to preview the transformation: https://webconfigtransformationtester.apphb.com/

as you can see it doesn't do anything. I've looked at a lot of examples, but obviously I'm missing something. Any help would be greatly appreciated.

(I've also tried this with no luck):

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.web>
      <compilation debug="false" xdt:Transform="Replace">
      </compilation >
  </system.web>
</configuration>

Solution

  • The transform works as intended on the mentioned online preview tool for web.config transformations https://webconfigtransformationtester.apphb.com/ when you change the namespace of the web.config file from

    <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
    

    to

    <configuration xmlns:xdt="http://schemas.microsoft.com/.NetConfiguration/v2.0">
    

    When this transform

    <?xml version="1.0" ?>
    <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
      <system.web>
        <compilation xdt:Transform="RemoveAttributes(debug)" />
      </system.web>
    </configuration>
    

    is applied to the adjusted web.config

    <?xml version="1.0" ?>
    <configuration xmlns:xdt="http://schemas.microsoft.com/.NetConfiguration/v2.0">
      <system.web>
        <compilation debug="true" targetFramework="4.0">
        </compilation>
      </system.web>
    </configuration>
    

    the debug attribute is removed from the result:

    <?xml version="1.0"?>
    <configuration xmlns:xdt="http://schemas.microsoft.com/.NetConfiguration/v2.0">
      <system.web>
        <compilation targetFramework="4.0">
        </compilation>
      </system.web>
    </configuration>
    

    Update: As mentioned in the comments, the configuration of the web.config file shouldn't have any namespace at all. Instead, it's necessary to add this import

    <xdt:Import assembly="AppHarbor.TransformTester" 
                namespace="AppHarbor.TransformTester.Transforms"/>
    

    to the transform file (at least, when testing with the mentioned online transformation tester):

    <?xml version="1.0"?>
    <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <xdt:Import assembly="AppHarbor.TransformTester" 
         namespace="AppHarbor.TransformTester.Transforms"/>
      <system.web>
        <compilation xdt:Transform="RemoveAttributes(debug)" />
      </system.web>
    </configuration>