I have created an appsettings.local.json to my project. In my start up file - configure method, I have added the below code:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) //load base settings
.AddJsonFile("appsettings.local.json", optional: true, reloadOnChange: true) //load local settings
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) //load environment settings
.AddEnvironmentVariables();
}
My application is still reading the original appsettings.json file and not the connection string from appsettings.local.json.
Did I miss out anything?
ConfigurationBuilderused for create configuration by your own. If you want do it, you should move your code toStartupconstructor and after that add next line:Where
Configurationis name of yourIConfigurationproperty.If you still want inject
IConfigurationto youStartupconstructor you can use this code at youIHostBuilderat Program.cs:Please check
context.HostingEnvironment.EnvironmentNamefor you framework version: my sample for netcoreapp3.1.