title: Setting environment variables in .NET Core 2.0
body: <p>I am trying to setting up multiple environments in my .NET Core 2.0 application. See my code below.</p>
  
  <h3>Configuration file (Launch.JSON)</h3>
  
  <pre><code>"configurations": [
      {
          "name": ".NET Core Launch (web)",
          "type": "coreclr",
          "request": "launch",
          "preLaunchTask": "build",
          // If you have changed target frameworks, make sure to update the program path.
          "program": "${workspaceRoot}/my.api/bin/Debug/netcoreapp2.0/my.api.dll",
          "args": [],
          "cwd": "${workspaceRoot}/my.api",
          "stopAtEntry": false,
          "requireExactSource": false,
          "internalConsoleOptions": "openOnSessionStart",
          "launchBrowser": {
              "enabled": true,
              "args": "${auto-detect-url}",
              "windows": {
                  "command": "cmd.exe",
                  "args": "/C start ${auto-detect-url}"
              },
              "osx": {
                  "command": "open"
              },
              "linux": {
                  "command": "xdg-open"
              }
          },
          "env": {
              "ASPNETCORE_ENVIRONMENT": "Development"
          },
          "sourceFileMap": {
              "/Views": "${workspaceRoot}/Views"
          }
      },
      {
          "name": ".NET Core Attach",
          "type": "coreclr",
          "request": "attach",
          "processId": "${command:pickProcess}"
      }
  ]
  </code></pre>
  
  <h3>Program.cs</h3>
  
  <pre><code>public class Program
  {
      public static void Main(string[] args)
      {
          BuildWebHost(args).Run();
      }
  
      public static IWebHost BuildWebHost(string[] args) =&gt;
          WebHost.CreateDefaultBuilder(args)
              .UseStartup&lt;Startup&gt;()
              .Build();
  }
  </code></pre>
  
  <h3>StartUp.cs</h3>
  
  <pre><code>public class Startup
  {
      public IContainer ApplicationContainer { get; private set; }
      private IHostingEnvironment HostingEnvironment { get; set; }
      public IConfigurationRoot Configuration { get; }
      private string ConnectionString
      {
          get
          {
              return this.HostingEnvironment.IsDevelopment() ? Configuration.GetConnectionString("DefaultConnection") : Configuration.GetConnectionString("Production");
          }
      }
  
      public Startup(IHostingEnvironment env)
      {
          var builder = new ConfigurationBuilder()
              .SetBasePath(env.ContentRootPath)
              .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
              .AddJsonFile($"appsettings.Development.json", optional: true, reloadOnChange: true)
              .AddJsonFile($"appsettings.Azuredev.json", optional: true, reloadOnChange: true)
              .AddEnvironmentVariables();
  
          Configuration = builder.Build();
  
          this.HostingEnvironment = env;
  
          System.Console.WriteLine(env.EnvironmentName); // Here it always give me Production.
      }
  </code></pre>
  
  <h3>My issue</h3>
  
  <p>I tried to use command line like <strong>dotnet run --environment "Development"</strong></p>
  
  <p>So, it should run on <strong>Development Environment</strong>, but it always runs with <strong>Production</strong>, (look I have added <strong>console.writeline</strong> in my <em>startup.cs</em> file)</p>
  
  <p>Now the strange thing is that if I use <kbd>F5</kbd> to Debug then it runs perfectly with the <strong>development</strong> environment.</p>