Set web.config transform in Asp.NET Core

There is a well-documented tool on github for xdt-transformations. Also it doesn't depend on command, both of dotnet publish and dotnet msbuild works fine

With the latest version of dotnet cli (2.1.400 or greater), you can just set this msbuild property $(EnvironmentName) and publish tooling will take care of adding ASPNETCORE_ENVIRONMENT environmentVariable to the web.config with the specified environment name.

Also, XDT support is available starting 2.2.100-preview1.


IIS Web Deploy ASP.NET Core (2.1) in Visual Studio 2017 (VS2017)

First do this: (ref:

  1. Install package - dotnet add package DotNet.Xdt --version 2.1.0
  2. Modify .csproj - add package - refer github
  3. Modify .csproj - add transform code (ApplyXdtConfigTransform) at the end - refer github
  4. Add web.DEV_Server.config transfor file by right-clicking on DEV_Server.pubxml
  5. Added following to web.DEV_Server.config

<environmentVariable xdt:Locator="Match(name)" name="ASPNETCORE_ENVIRONMENT" value="Development" xdt:Transform="SetAttributes" />

  1. Modify DEV_Server.pubxml to modify following setting value.


  1. Validate Connection & Publish

Deploy still uploads other config files, not sure how to stop that.

This worked for me:

  1. Add web.release.config file to the project root.
  2. In Visual Studio 2017, Publish using Web Deploy (make sure it is set to Release). Settings will automatically be picked up.

Sample transformation:

    <?xml version="1.0"?>
    <configuration xmlns:xdt="">
              <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="PRODUCTION" xdt:Locator="Match(name)" xdt:Transform="SetAttributes" />

Update: If you want to remove web.config.release file and others on publish, simply edit your .csproj file and add something like this:

    <Content Remove="appsettings.Development.json" />
    <Content Remove="web.release.config" />
    <None Include="appsettings.Development.json" />
    <None Include="web.release.config" />