How to consolidate config files in an asp.net solution?

I have several projects and a website in a large asp.net solution. In some projects I have an app.config file and on a website I have my web.config. In each configuration, I specify a few things that are common among them, such as connection strings. Is there a way to combine these common elements into a single config file and specify which of the various projects that need them?

+1


source to share


2 answers


You can link to external config files in any .config (see http://www.peterprovost.org/blog/post/External-Config-Files-in-NET.aspx ).

Each project has a configuration file; these files are published in the bin directory as [output name] .config (for example, MyCode.DLL, MyCode.DLL.config). Then you can reference these .config files from your main config (web.config).



If you find that your config files are not finding the path to the correct destination, you can take the message compilation step mentioned by ChanChan.

+1


source


You can do this with the pre / post compile step in the project to copy the config file from the solutions directory.



Several years ago, this was the solution recommended by Scott Hanselman.

+1


source







All Articles