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?
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.
If you have a web application project, Right-click on web. config and choose Add Config Transform. This will add any config transforms that are missing from your project based on build configurations (i.e. if you have Production and Staging build configs, both will get a transform added).
The xdt:Transform attribute value "SetAttributes" indicates that the purpose of this transform is to change attribute values of an existing element in the Web. config file.
This package allows you to automatically transform your app. config (or any file) when you press F5 in Visual Studio. You can have different transformations based on the build configuration. This will enable you to easily have different app settings, connection strings, etc for Debug versus Release.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With