Closed imxavi closed 5 years ago
Can you show appsettings.json and the related environment variables?
Also, try making appsettings.json optional: false
to make sure the file is being found correctly.
Hi, sorry let me explain better. I did 2 scenarios: A) using just CreateDefaultBuilder without UseConfiguration var hostBuilder = WebHost.CreateDefaultBuilder(args);
var settingName = "SHUTDOWNTIMEOUTSECONDS"; var settingStrShutdownTimeout = hostBuilder.GetSetting(settingName);
B) add UseConfiguration with the code above in the initial question. files are with:
- launchSettings.json:
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_SHUTDOWNTIMEOUTSECONDS" : "50"
}
- appsettings.json:
"SHUTDOWNTIMEOUTSECONDS": 30
I was expecting to get 50 because in LoadConfiguration we do AddEnvironmentVariables() after AddJsonFile("appsettings.json"...)
Thanks in advance.
AddEnvironmentVariables isn't working because you need to specify the prefix in order for the matching to work correctly: AddEnvironmentVariables("ASPNETCORE_")
.
hostBuilder.GetSettings reads only from the host config, where appsettings isn't loaded later until the app's config is build. That's why UseConfiguration works, it loads the config immediately into the host config.
Hi, understood. Thank You.
Hi, I have this:
I was expecting 2 things: a) get SHUTDOWNTIMEOUTSECONDS from appsettings, but it gets null b) if SHUTDOWNTIMEOUTSECONDS is in appsettings.json with 30 and launchSettings.json (env var) with 50, I was expecting 50 due to Loadconfiguration order. i.e, env var overrides previous value set. but I am getting always what is in appsettings. Is I use new WebHostBuilder()instead of WebHost.CreateDefaultBuilder is the same behavior. Some light on what I am doing wrong please. Thanks