I'm developing a .NET Core
(.NET 6
) WPF
app, and I have a problem detecting the dev environment (Development or Production).
I'm creating a IHost
when my WPF app starts, in order to use Dependency Injection and all the other .NET Core goodies, like this:
public partial class App : Application
{
private readonly IHost host;
public App()
{
host = Host.CreateDefaultBuilder()
.UseContentRoot(CoreConstants.MaintenanceToolBinFolder)
.ConfigureServices((context, services) =>
{
var configuration = context.Configuration;
//...
})
.Build();
}
}
Now, in an ASP.net Core
web app this would automatically read the ASPNETCORE_ENVIRONMENT environmental variable and use it to determine the current environment. However, this is completely ignored here, and the environment is always "Production".
What is the proper way to detect the environment in this case? Should I just manually read the variable and set the environment, or is there a more "proper" way?