Skip to content

Transformations

A basic app config may look like:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<addkey="foo"value="my foo"/>
<addkey="bar"value="my bar"/>
</appSettings>
<connectionStrings>
<addname="test"providerName="my provider"connectionString="my connection string"/>
</connectionStrings>
</configuration>

A Transformation config may look like:

<?xml version="1.0" encoding="utf-8" ?>
<configurationxmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<addkey="foo"value="transformed"xdt:Transform="Replace"xdt:Locator="Match(key)"/>
<addkey="Environment"value="Dev"xdt:Transform="Insert "/>
</appSettings>
</configuration>

After running the transform from either the automatic build task, at runtime or with the .NET CLI Tool the resulting app.config will look like:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<addkey="foo"value="transformed"/>
<addkey="bar"value="my bar"/>
<addkey="Environment"value="Dev"/>
</appSettings>
<connectionStrings>
<addname="test"providerName="my provider"connectionString="my connection string"/>
</connectionStrings>
</configuration>

XDT Transformations

While the XDT namespace allows you to radically change your app.config. In most cases however you will only need to focus on the xdt:Transform attribute.

  • Insert
  • InsertBefore(XPath expression)
  • InsertAfter(XPath expression)
  • Remove
  • Remove All

To find out more about the available transformations, see the microsoft documentation.

Replace

This transformation requires the xdt:Locator attribute to function correctly. In most cases this will be a simple match on the key attribute:

<addkey="foo"value="transformed"xdt:Transform="Replace"xdt:Locator="Match(key)"/>

See the documentation for all the ways in which the xdt:Locator attribute can be used.

Copyright © 2017 - 2021 Dan Siegel

AltStyle によって変換されたページ (->オリジナル) /