title: Azure DevOps - .NET Core Build Include Web.config file
body: <p>I'm using Azure DevOps for building and releasing a .NET Core MVC web application to a Windows Server 2016 EC2 instance in AWS.</p>
  
  <p>I have different environments, so I've created the following appsettings.json files:</p>
  
  <ul>
  <li>appsettings.DEV.json </li>
  <li>appsettings.STG.json </li>
  <li>appsettings.PRD.json</li>
  </ul>
  
  <p>After some research, I see that we can set the ASPNETCORE_ENVIRONMENT variable in the web.config file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
      &lt;location path="." inheritInChildApplications="false"&gt;
      &lt;system.webServer&gt;
        &lt;handlers&gt;
          &lt;add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" /&gt;
        &lt;/handlers&gt;
        &lt;aspNetCore processPath="dotnet" arguments=".\www.MyApp.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout"&gt;
        &lt;environmentVariables&gt;
          &lt;environmentVariable name="ASPNETCORE_ENVIRONMENT" value="[ENV]" /&gt;
        &lt;/environmentVariables&gt;
        &lt;/aspNetCore&gt;
      &lt;/system.webServer&gt;
    &lt;/location&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>I can then load the respective environment appsetting.json file using the following code in Program.cs:</p>
  
  <pre><code>public class Program
      {
          public static void Main(string[] args)
          {
              CreateWebHostBuilder(args).Build().Run();
          }
  
          public static IWebHostBuilder CreateWebHostBuilder(string[] args) =&gt;
              WebHost.CreateDefaultBuilder(args)
                  .ConfigureAppConfiguration(ConfigConfiguration)
                  .UseStartup&lt;Startup&gt;();
  
          static void ConfigConfiguration(WebHostBuilderContext ctx, IConfigurationBuilder config)
          {
              config.SetBasePath(Directory.GetCurrentDirectory())
                  .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                  .AddJsonFile($"appsettings.{ctx.HostingEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: true);
  
          }
      }
  </code></pre>
  
  <p>For each deployment, I would like to control the web.config that gets deployed so that I can control the value of ASPNETCORE_ENVIRONMENT.  Similar to web.config transform in a traditional ASP.NET environment.</p>
  
  <p>Is there a way to do this in Azure DevOps, or via a setting in Visual Studio?  I've read that .NET Core 2.2 will offer a solution for this, but what can be done in the meantime? </p>