Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
234 views
in Technique[技术] by (71.8m points)

c# - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...