Take a look at the documentation for CreateDefaultBuilder()
Remarks
The following defaults are applied to the returned WebHostBuilder:
use Kestrel as the web server and configure it using the application's configuration providers,
set the ContentRootPath to the result of GetCurrentDirectory(),
load IConfiguration from appsettings.json and appsettings.[EnvironmentName].json,
load IConfiguration from User Secrets when EnvironmentName is 'Development' using the entry assembly,
load IConfiguration from environment variables,
load IConfiguration from supplied command line args,
configure the ILoggerFactory to log to the console and debug output,
and enable IIS integration.
Number 3 in that list is always going to look at the value of the ASPNETCORE_ENVIRONMENT environment variable (defaults to "Production" if not specified), and attempt to load an appsettings file with that name.
Rather than change your code, or using preprocessor directives, just change the value of that environment variable (to, for example, "Development").
This is how your launchSettings.json file works:
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
...
Don't fight with CreateDefaultBuilder() - your posted code does so many steps that the method already does for you (loading files, setting the base path, etc).
This is the default Program.cs given to you with ASP.Net Core projects, and it will work for you just fine:
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
Also, just a note, you're loading environment specific files before the main appsettings.json file. Usually you'll want to do that in the other order.
appsettings.jsonhave? production or dev?