I’m using .NET 6.0, my appsettings.json
looks like this:
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
"Client_Version": {
"Name_of_client": "Mordor",
"Environment_of_client": "PROD"
}
}
Based on Name_of_client
and Environment_of_client
at runtime, different appsettings.json
is used. In this case appsettings.Mordor.PROD.json
is being used.
When I publish a profile like this mordor-prod.pubxml
, I want that this appropriate appsettings.json
is published.
And when using publish profile like this mordor-stage.pubxml
to publish appsettings.json
with this:
"Client_Version": {
"Name_of_client": "Mordor",
"Environment_of_client": "STAGE"
}
In .NET Core 2.1, I’m using a web.config
with a xdt:Transform
, and works fine.
Not easy to do with just .NET, IMO, I think you’ll need additional tools.
But even if you can’t change the appsettings.XXX.json file, you can change the configuration in code. As you know, the appsettings.XXX.json file (and other sources, such as environment variables, user secrets, and possibly others) are put together inside the IConfiguration
instance automatically (in ASP.NET Core, for console, you need to do it yourself). From there, you are free to modify the values. See also Using ASP.NET Core’s ConfigurationBuilder in a Test Project.