title: Running .NET Core API Linux Environment Launch Profiles
body: <p>So I'm trying to get a .NET Core API application running with different environment settings.  I've been reading the documentation and as far as I can tell I've followed the instructions.  Yet when I run the service outside of VS it blows up due to not being able to find a connection string.  I'm clearly missing something basic.</p>
  
  <p>I've setup two profiles in <code>launchSettings.json</code> "Development" and "Staging"</p>
  
  <pre><code>"profiles": {
    "IIS Express": {
      "commandName": "Project",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "Development": {
      "commandName": "Project",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "Staging": {
      "commandName": "Project",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Staging"
      }
    }
  </code></pre>
  
  <p>I have the following configuration files.</p>
  
  <pre><code>appsettings.json
  appsettings.Development.json
  appsettings.Staging.json
  </code></pre>
  
  <p>I also have the following code in in my <code>Startup.cs</code>:</p>
  
  <pre><code>var builder = new ConfigurationBuilder()  
      .SetBasePath(env.ContentRootPath)
      .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
      .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: false, reloadOnChange: true)
      .AddEnvironmentVariables();
  
  Configuration = builder.Build();
  </code></pre>
  
  <p>When I debug this I can see that <code>.AddJsonFile($"appsettings.{env.EnvironmentName}.json"</code> is loading the expected file.  However, when I publish this to a directory and attempt to run it the <code>connectionString</code> value us <code>null</code>.</p>
  
  <p>appsettings.json doesn't contain a value for the connection string. It is in the two environment dependent files, defined like:</p>
  
  <pre><code>"DefaultConnection": {
      "ConnectionString":
          "Server=name;Port=3307;Database=name;User Id=name;Password=name;"
  },
  </code></pre>
  
  <p>Since this all works inside VS I'm sure this is all correct.  However when I try to run it, BOOM!</p>
  
  <pre><code>dotnet MyDll.dll --launch-profile Staging
  </code></pre>
  
  <p>I've just noticed that <code>--launch-profile</code> only works with <code>dotnet run</code> and that when I try to run the application it's looking for a <code>Production.json</code> file.  How do I use the various profiles with just the <code>dotnet</code> command, not the <code>dotnet run</code> command?</p>