I like to split my app.config
into a user specific part and an application specific part. Is it possible to store a part of the app.config
in another file?
I already tried this:
<!DOCTYPE cruisecontrol [<!ENTITY email SYSTEM "email.config">] >
but this does not load.
Is there another possiblity without changing the application itself?
We will start with creating an class that can store the instance settings (the <add> element), then we'll create a collection that can store our instances (the <instances> element) and then we'll create the class to manage the Configuration Section (the <sageCRM> element).
The file is stored inside this path "bin/debug/app. config", if you make changes while debugging, those changes should appear there. Just remember that this file is overwritten with the "app. config" from the project root each time you run the application on Visual Studio IDE.
Now you might be wondering what happens behind the scenes. Well, when you compile your application, the compiler actually copies the app. config file to the output folder, but gives it another name: When you start your application (ConsoleApp1.exe in our example), the matching config file will be loaded too.
You can use the configSource
attribute to tell the framework to load a particular section from another file.
For example, if you had a config file with a section like this:
<connectionStrings>
<add name="MyDatabase" connectionString="...etc..." />
</connectionStrings>
You could replace it with:
<connectionStrings configSource="ConnectionStrings.config" />
...and create a file ConnectionStrings.config
with the contents of the original section (including the <connectionStrings>
node - exactly the same as my first code section above).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With