开发者

C# can we have multiple .config file for a project?

If we can have more than one .config files, we can share one config file with other projects and put private configuration into another. Visu开发者_JAVA技巧al Studio 2008 will be confused?


No, except for the <appSettings> node which has a special file= attribute which works in a "cummulative" manner, all configuration sections are single shot affairs - you have it, and you have one of it exactly - or you have nothing.

<appSettings file="common.appsettings.config">
   <add key="private1" value="value1" />
</appSettings>

This will read in the contents of the common.appsettings.config file and anything that's not being overwritten by an explicit value in your own config here is being used from that external config file.

You cannot add additional "private" info to an existing configuration section, as far as I know.


Visual Studio 2010 has support for multiple .config files. It is one feature of new web application packaging and deployment system. We can create now separate web.config files for each configuration we have for application. But for 2008 there are no support for multi config files, you can workaround this by adding two config files and rename them in build time

Example:

private.config public.config

on pre-msbuild event merge these two files

rename merged file, it should be web.config or app.config

Hope this helps...

s


You can have multiple web config for each directory although only one config section handler.


The configuration files are hierarchical from general to specific. Configuration files further down in the hierarchy override any settings from the previous ones. So if you have a solution that includes a master web.config file, any web.config files in your projects override it and are specific and visible only to those projects. If a project is comprised of several folders, you can add a web.config file to each of those as well, again with different settings that also override any of those set above. But I caution over-engineering this or you may have difficulty with a trickle-down of certain property values or loopholes in security if it is security that you are configuring at each level.


Each config section can be put in an external file, and referenced from the main app.config / web.config via the configSource attribute. However, you will have to write custom section handlers for each custom section / external config file that you want to write, which may get a little tedious. In addition, the appSettings section can be externalised and referenced via the same mechanism.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜