Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load parts of App.Config from another file

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?

like image 845
schoetbi Avatar asked Jul 28 '09 12:07

schoetbi


People also ask

How do I add a config section in app config?

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).

Where are app config files stored?

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.

Does app config get compiled?

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.


1 Answers

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).

like image 96
Jon Grant Avatar answered Oct 06 '22 05:10

Jon Grant