Search code examples
c#asp.netvisual-studioweb-config

Does the appsettings file attribute override what is in the app.config?


The appsettings tag in the app.config has a file attribute:

<appSettings file="other.config">
..
..
</appSettings>

How does this work? Will it merge what is in the appSettings (original) with the other.config file? Or will it overwrite it? What if the other.config file doesn't exist, should it crash?

I'm trying it myself and if a key isn't in the original, it doesn't seem to read it from the other.config?

Should the other.config file have just xml nodes, or should it all be inside an appsettings element?

<appSettings>
  <userId>123</userId>
</appSettings>

or

<userId>123</userId>

Solution

    • If the file doesn't exist it will not crash, it will just be ignored.
    • The external config has to contain the <appSettings> node so your first example is correct.
    • The value in the external file will take priority, if no value is present then the app.config value is used.

    Does that cover off everything?