In my project i have the following files:
appsettings.json and appsettings.Development.json
so the idea is to load the file appsettings.Development.json in the Development environement and the appsettings.json for the production environement.
in the launchSettings.json i changed the ASPNETCORE_ENVIRONMENT to Development:
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
this works as expected as the :
env.IsDevelopment() is true
the appsettings is loaded like this:
var config = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", true, true)
.Build();
but still all the values are loaded from the appsettings.json and not the appsettings.Development.json.
i also tried:
var config = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", true, true)
.AddJsonFile("appsettings.Development.json", true, true)
.Build();
but the values are always loaded from the last file in this case appsettings.Development.json even if the :
env.IsDevelopment() is false