1
2public Startup()
3{
4 var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
5
6 configuration = new ConfigurationBuilder()
7 .SetBasePath(Directory.GetCurrentDirectory())
8 .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
9 .AddJsonFile($"appsettings.{environment}.json", optional: true)
10 .AddEnvironmentVariables()
11 .Build();
12}
13
14
1All that’s required is to add the following NuGet packages and an appsettings.json file.
2
3Microsoft.Extensions.Configuration
4Microsoft.Extensions.Configuration.FileExtensions
5Microsoft.Extensions.Configuration.Json
6
7The appsettings.json files “Copy to Output Directory” property should also be set to “Copy if newer” so that the application is able to access it when published.