title: ASP.NET Core hosting environment variable ignored
body: <p>I have two web sites on my staging server, and both are ASP.NET Core sites that run in IIS. I have set the environment variable <code>ASPNETCORE_ENVIRONMENT</code> to <code>Staging</code> machine-wide. This works well for one of the sites, however the other ignores the variable and runs in production mode instead. I have to configure the hosting environment into the <code>web.config</code> file to run it in staging mode.</p>
  
  <p>Why does one site not take the environment variable into account?</p>
  
  <p>In both of my <code>Startup(IHostingEnvironment env)</code> constructors, I use the environment variables:</p>
  
  <pre><code>public Startup(IHostingEnvironment env)
  {
      var builder = new ConfigurationBuilder()
          .SetBasePath(env.ContentRootPath)
          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
          .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
          .AddJsonFile("logging.json")
          .AddEnvironmentVariables();  //   &lt;---
          Configuration = builder.Build();
      }
  </code></pre>