schoetbi
schoetbi

Reputation: 12856

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?

Upvotes: 14

Views: 9373

Answers (1)

Jon Grant
Jon Grant

Reputation: 11530

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

Upvotes: 28

Related Questions