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
163 views
in Technique[技术] by (71.8m points)

c# - How do you manage .NET app.config files for large applications?

Suppose a large composite application built on several foundation components packaged in their own assemblies: (database reading, protocol handlers, etc.). For some deployments, this can include over 20 assemblies. Each of these assemblies has settings or configuration information. Our team tends to like the VS settings editor (and the easy-to-use code it generates!), and the application vs. user distinction meets most of our needs.

BUT....

It is very tedious to copy & paste the many configuration sections into our application's .xml. Furthermore, for shared components that tend to have similar configurations across applications, this means we need to maintain duplicate settings in multiple .config files.

Microsoft's EntLib solves this problem with an external tool to generate the monster .config file, but this feels klunky as well.

What techniques do you use to manage large .NET .config files with sections from multiple shared assemblies? Some kind of include mechanism? Custom configuration readers?

FOLLOWUP:

Will's answer was exactly what I was getting at, and looks elegant for flat key/value pair sections. Is there a way to combine this approach with custom configuration sections ?

Thanks also for the suggestions about managing different .configs for different build targets. That's also quite useful.

Dave

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

You use one master config file that points to other config files. Here's an example of how to do this.


In case the link rots, what you do is specify the configSource for a particular configuration section. This allows you to define that particular section within a separate file.

<pages configSource="pages.config"/>

which implies that there is a file called "pages.config" within the same directory that contains the entire <pages /> node tree.


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

...