You don’t need to change appsettings.json. The core project can retrieve data from appsettings.[environment].json
file per to ASPNETCORE_ENVIRONMENT
environment variable.
For example:
- Add corresponding
appsettings.[environment].json
files to project, such as appsettings.Production.json
, appsettings.Development.json
and set the corresponding value in each files.
- Code in Startup file
:
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
- Set/add
ASPNETCORE_ENVIRONMEN
T environment variable to each environment machine (just need to set/add once)
There are some articles that can help you:
Configuration in ASP.NET Core
Working with multiple environments
If you still want to change appsettings.json file, you can unzip packaged file, then update file by using Token task (e.g. Replace Tokens), then zip these files.
More information, you can refer to Managing Config for .NET Core Web App Deployments with Tokenizer and ReplaceTokens Tasks