The Development, Staging and Release environments are good enough for most projects. But what if you have one of the situations where you need more?

One of the solutions I work with has some fun requirements and adding more environments allows us to easily cope for additional scenarios. The documentation Microsoft has put together for this is actually quite good and shows much of the flexibility for it. Too good of a job, actually, it’s a little overwhelming. So this is as much to help me remember how to do this in the future as anything.

  1. Add the additional environments to launchSettings.json. These will now show as options in the box next to the play arrow in Visual Studio. We have multiple dev and release scenarios, so we’ll add DBG-X, DBG-Y, REL-X, and REL-Y.
  2. "DBG-X": {
          "commandName": "IISExpress",
          "launchBrowser": true,
          "environmentVariables": {

  3. Add appsettings.json files for each of the new environments, such as appsettings.DBG-X.json. The call in Program.cs to WebHost.CreateDefaultBuilder() will now pick up the respective version for each environment. And it even magically knows to nest these under appsettings.json in Visual Studio.
  4. Since we have multiple development environments (DBG-X and DBG-Y) and are no longer using the Development environment, the condition in Startup.Configure using env.IsDevelopment will no longer work. We need a custom version. ASP.Net Core gives multiple ways of doing this, so you could create custom versions of Startup.cs, Configure(), or ConfigureServices() for each environment if you need to. That’s overkill for me at the moment, so I’ll just check if the environment name starts with “DBG-“.
    if(env.EnvironmentName.StartsWith("DBG-")) {…

And that’s really it. Hope this helps!