Skip to content

Generic Host Builder and HostingEnvironment.IsDevelopment #4150

@Eilon

Description

@Eilon

From @dazinator on July 5, 2018 17:7

I am using the new generic host in 2.1.0 as documented here: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/generic-host?view=aspnetcore-2.1

When the hosting environment is development, I'd like to add user secrets:

  .ConfigureAppConfiguration((hostContext, configApp) =>
                   {
                       configApp.AddJsonFile("appsettings.json", optional: true);                   
                       if (hostContext.HostingEnvironment.IsDevelopment())
                       {
                           configApp.AddUserSecrets<Program>();
                       }
                       configApp.AddEnvironmentVariables(prefix: "FOO_");
                       configApp.AddCommandLine(args);
                   })

However IsDevelopment always returns false.
Yet I have set the ASPNETCORE_ENVIRONMENT enironment variable. Here is my launch settings:

{
  "profiles": {
    "Foo": {
      "commandName": "Project",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

It would make sense if ASPNETCORE_ENVIRONMENT was no longer used to control this for a generic host as we are not in asp.net core land - but in that case is there now a different environment variable name for this, or do we set the Environment name ourselves in code?

Copied from original issue: #3298

Metadata

Metadata

Assignees

Labels

DoneThis issue has been fixedarea-hostingIncludes Hostingarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsenhancementThis issue represents an ask for new feature or an enhancement to an existing one

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions