title: Publish not getting connection string from appsettings.production.json
body: <p>I am not able to get my published ASP.net Core application to switch to using the connection string in my appsettings.production.json file.  </p>
  
  <p>I have setup the launchSettings to use the ASPNETCORE_ENVIRONMENT environment variable for my Development and Production profiles.  When I switch the profiles and run them in visual studio, my connection string changes properly.  </p>
  
  <p>When I run the published app on my Ubuntu server, it does not switch.  I have set the ASPNETCORE_ENVIRONMENT variable to "Production" on my server.  I have also verified that both the appSettings.json and appSettings.production.json exist in the root directory for the application.</p>
  
  <p>My appsettings.json file:</p>
  
  <pre><code>{
    "Logging": {
      "IncludeScopes": false,
      "LogLevel": {
        "Default": "Debug",
        "System": "Information",
        "Microsoft": "Information"
      }
    },
    "ConnectionStrings": {
      "DefaultConnection": "server=localhost;user id=root;password=dev;database=testdb;sslmode=none",
    }
  }
  </code></pre>
  
  <p>my appsettings.production.json file:</p>
  
  <pre><code>{
    "ConnectionStrings": {
      "DefaultConnection": "server=localhost;user id=root;password=prod;database=testdb;sslmode=none"
    }
  }
  </code></pre>
  
  <p>My launchSettings.json file:</p>
  
  <pre><code>{
    "iisSettings": {
      "windowsAuthentication": false,
      "anonymousAuthentication": true,
      "iisExpress": {
        "applicationUrl": "http://localhost:50824/",
        "sslPort": 0
      }
    },
    "profiles": {
      "IIS Express": {
        "commandName": "IISExpress",
        "launchBrowser": true,
        "launchUrl": "home/index",
        "environmentVariables": {
          "ASPNETCORE_ENVIRONMENT": "Development"
        }
      },
      "IIS Express (Production)": {
        "commandName": "IISExpress",
        "launchBrowser": true,
        "launchUrl": "home/index",
        "environmentVariables": {
          "ASPNETCORE_ENVIRONMENT": "Production"
        }
      }
    }
  }
  </code></pre>
  
  <p>My Startup.cs:</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);
  
      if (env.IsEnvironment("Development"))
      {
          // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.
          builder.AddApplicationInsightsSettings(developerMode: true);
      }
  
      builder.AddEnvironmentVariables();
      Configuration = builder.Build();
  
  
      Console.WriteLine("Root Path: " + env.ContentRootPath);
      Console.WriteLine("Connection String: " + Configuration.GetConnectionString("DefaultConnection"));
  }
  </code></pre>
  
  <p>I have referenced these questions already but no luck:</p>
  
  <p><a href="https://stackoverflow.com/questions/39215806/asp-net-core-1-appsettings-production-json-not-updating-connection-strings">asp.net core 1 appsettings.production.json not updating connection strings</a></p>
  
  <p><a href="https://stackoverflow.com/questions/37858312/dotnet-publish-doesn%C2%B4t-publish-correct-appsettings-env-environmentname-json">dotnet publish doesn´t publish correct appsettings.{env.EnvironmentName}.json</a></p>