Marco G
Marco G

Reputation: 703

How to apply two different transformations on one web.config element?

From my VS2010 deployment project I would like to apply two different transformations to two different attributes of one element in my web.config. Consider the following web.config snippet:

<exampleElement attr1="false" attr2="false" attr3="true" attr4="~/" attr5="false">
  <supportedLanguages>
    <!-- Some more elements here -->
  </supportedLanguages>
</exampleElement>

Now how can I change attribute 'attr1' and remove attribute 'attr5' in the transformed web.config? I know how to perform the individual transformations:

<exampleElement attr1="true" xdt:Transform="SetAttributes(attr1)"></exampleElement>

and:

<exampleElement xdt:Transform="RemoveAttributes(attr5)"></exampleElement>

But I don't know how to combine these transforms. Anybody?

EDIT:

Can't answer my own question yet, but the solution seems to be:

It seems that it is possible to repeat the same element with different transformations, like so:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <exampleElement attr1="true" xdt:Transform="SetAttributes(attr1)"></exampleElement>
    <exampleElement xdt:Transform="RemoveAttributes(attr5)"></exampleElement>
</configuration>

As said, this seems to work, but I'm not sure whether this is the intended use of the web.config transformation syntax.

Upvotes: 15

Views: 4391

Answers (2)

Marco G
Marco G

Reputation: 703

As Nick Nieslanik confirmed this is done by repeating the same element with different transformations, like so:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <exampleElement attr1="true" xdt:Transform="SetAttributes(attr1)"></exampleElement>
    <exampleElement xdt:Transform="RemoveAttributes(attr5)"></exampleElement>
</configuration>

Upvotes: 21

Ludwo
Ludwo

Reputation: 6173

I'm using XmlPreprocess tool for config files transformations & manipulation. It is using one mapping file for multiple environments. You can edit mapping file by Excel. It is very easy to use. You can update your config files with xmlpreprocess and use configuration (debug, dev, prod,...) as a parameter for the different setup...

Upvotes: 0

Related Questions