For each environment you need to create a separate appsettings.{EnvironmentName}.json files:
Then open project.json file and include them into "include" in "publishOptions" section. This lists all the files and folders that will be included when you publish:
"publishOptions": {
"include": [
"appsettings.Development.json",
"appsettings.Staging.json",
"appsettings.Production.json"
...
]
}
The final step. In your Startup class add:
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
in constructor where you set up configuration sources:
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();