Have been looking for the right way to add configurations to my dot net core 2.0 web API.
Until now what I have done is:
Added appsetteings.Development.json, appsetteings.Production.json
In program.cs:
public static IWebHost BuildWebHost(string[] args) { return WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .ConfigureAppConfiguration((hostContext, config) => { var env = hostContext.HostingEnvironment; config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true); }) .Build(); }In startup.cs
public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.Configure<dynamic>(Configuration); }
The issue is whenever I debug my code it always takes settings from appsettings.Development.json.
I also found that the hostContext.HostingEnvironment.EnvironmentName always comes as development regardless of which environment I pick to debug in.
