How-To's

XDT configuration transformations in Rider

Rider 2017.3 EAP comes with support for Web.config and App.config transformations. These configuration transformations allow us to update certain settings in a Web.config or App.config file when packaging the application. For example, we may want to update the database connection string for a Release build, or update certain settings for a Debug build.

Using the context menu in Solution Explorer or in the editor, we can generate a configuration transform file for any of our solution’s configuration files. Optionally, we can nest the file under its parent configuration, too.
Add new XDT config transformation

Rider generates a sample configuration transform file with certain pointers to the XDT transformation syntax. We could write a transformation that updates a connection string, and removes the debug="true" attribute from our Web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <!-- Replace connection string -->
  <connectionStrings>
    <add name="MyDB"
         connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
         xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
  </connectionStrings>

  <system.web>
    <!-- Drop debug attribute -->
    <compilation xdt:Transform="RemoveAttributes(debug)" />
  </system.web>
</configuration>

While these transformations should be run using MSBuild, for example when using WebDeploy, Rider provides support for previewing (and running) them in the IDE. This lets us validate the XDT transformation we are working on, without having to run a full build each time.

The configuration transformation preview shows in a diff viewer, so we can see exactly which elements or attributes will be updated:
Preview XDT config transformation in Rider

Note in earlier versions of Rider, XDT configuration transformations are available as a plugin.

Download Rider 2017.3 EAP and give it a try!

image description