The central configuration file is appsettings.json , and you can have several files, such as appsettings.Production.json , etc. that will be downloaded and override the settings from appsettings.json .
for example
// Set up configuration sources. var builder = new ConfigurationBuilder() .SetBasePath(hostEnv.ContentRootPath) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .AddJsonFile($"appsettings.{hostEnv.EnvironmentName}.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables();
All you need for this is an environment variable to set the environment type (see the documentation here ).
You can also override environment variables if you add AddEnvironmentVariables() to your configuration constructor. Therefore, if you have appsettings.json
{ "Data" { "Default" { "ConnectionString" : "..." } } }
and you want to override this through an environment variable, you have to set up an environment variable called "Data: Default: ConnectionString" and this value will override the parameters in appsettings.config and appsettings.Production.config with the value from the environment variable.
You can find more details in the official documentation here .
Tseng
source share