Search code examples
.net-coreasp.net-core-hosted-services

NetCore Host.CreateDefaultBuilder doesn't get Development configurations


I'm trying to create a background task within a console app.

But my host is not being configured correctly, it's saying i'm in production even if i've added an environment variable "ASPNETCORE_ENVIRONMENT":"Development" on my machine.

I need this to get the UserSecrets added to the configuration while developping. It's working in a WebProject but i need the same for the console app.

What am i doing wrong ?

Here is the code

    private static IHostBuilder CreateHost(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureServices((context, services) =>
            {
                // Here => there is no UserSecrets in the configurations.

                services.AddInfra(context.Configuration);
                services.AddAppCore();

                services.AddHostedService<MyBackgroundService>();
            });

Solution

  • If i was not reading too fast those documentation, i would have found it earlier...

    WebServer = ASPNETCORE_ENVIRONMENT
    Service = DOTNET_ENVIRONMENT
    

    With the new environment variable DOTNET_ENVIRONMENT set to "Development" everything is fine!