XDT configuration transformations in Rider

Posted on by Maarten Balliauw

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!

Comments below can no longer be edited.

13 Responses to XDT configuration transformations in Rider

  1. Kira says:

    December 20, 2017

    Is that possible to use this transformation in core projects?
    I know, I should use json config file, but I just wonder if it is possible

    • Maarten Balliauw says:

      December 20, 2017

      You can – Rider will provide the menu item. To run transforms as part of a build, you may have to add an additional msbuild step to your project file(s).

  2. Ilya says:

    February 5, 2018

    Just installed 2017.3 and does’t have such menu item. Why?

    • Maarten Balliauw says:

      February 5, 2018

      On what filename are you checking? Can you check in solution explorer?

  3. Ilya says:

    February 6, 2018

    I have created ASP.NET Web Application (net4.5) with Rider 2017.3 wizard, then click Web.config in Solution Explorer. There is no “Config Transformation” menu item.

    • Maarten Balliauw says:

      February 6, 2018

      Indeed, the menu is not showing. I made a bug report for this so we can fix this for the next release (https://youtrack.jetbrains.com/issue/RIDER-13380)

      As a workaround, you could:
      1) Select the Web.config file
      2) Use Ctrl+T / double-shift and type “transform”
      3) This will show the add transformation/perform transformation/… menu entries

  4. Orest says:

    April 23, 2018

    Please advise how to deal with transformations of app.config file.
    In VS 2015/2017 it’s possible to implement with extension named Slowcheetah. Building sln file with such transformations in Rider is not successful. What should be done to fix the issue?

    • Maarten Balliauw says:

      April 23, 2018

      Slowcheetah should just work, Rider calls msbuild to run your build, and as Slowcheetah is part of that pipeline it should run nicely.

      Other option is use the menu in Rider and do it manually, which is also supported.

      • Eric Berger says:

        May 17, 2018

        Could you describe the “use the menu in Rider” option?
        A way not involving Slowcheetah seems smoother to spread over a dev team.

        • Maarten Balliauw says:

          May 17, 2018

          That would be this blog post 🙂

          • Eric Berger says:

            May 17, 2018

            Ok, got it!
            Sorry, I just skipped this part, current implementation is great!
            It would be brilliant to (optionally) execute the transform on build. Shouldn’t be a big deal as preview/perform transform is already implemented on a user trigged basis.

            • Maarten Balliauw says:

              May 17, 2018

              Cool, thanks for the suggestion!

            • Edwin Goddard says:

              August 7, 2019

              That would be great if you could implement this on build in an easy manner like SlowCheetah does.

Subscribe

Subscribe to .NET Tools updates