0

I have the following on an ASP.NET Core Startup:

builder
  .AddJsonFile("config.json", false)
  .AddJsonFile($"config.{hostingEnvironment.EnvironmentName}.json", true);

This way I can use the config files:

config.json
config.development.json
config.production.json
config.staging.json

If I have a property that is different in production but the same in development and staging should I place that property on config.json and other one in production to replace the valie in config.json?

Or do I need to add the property in config.development.json, config.production.json and config.staging.json and remove it from config.json?

I mean, is there property replacement in ASP.NET Core configs like there was in Web.config of ASP.NET 4?

2
  • 1
    if you have more than one configuration source and the property exists in more than one source, then the last source wins, so the order of adding configuration sources is important Commented Apr 29, 2016 at 18:42
  • In my case I always add config.json first and one of the other after, so that means that I have a property in config.json and another value only in config.production.json to replace the base one. This was what I wasn't sure ... Thanks Commented Apr 29, 2016 at 18:46

1 Answer 1

1

Here is the source code that shows that config files are traversed in reverse order link

foreach (var provider in _providers.Reverse())

Any key in config.{hostingEnvironment.EnvironmentName}.json would override same key in config.json

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.