Aaron Palmer
Aaron Palmer

Reputation: 8992

How to consolidate config files in asp.net solution?

I have several projects and a website in a large asp.net solution. In some of projects I have an app.config file and in the website I have my web.config. In each config I specify several things that are common amongst them, such as connection strings. Is there any way to consolidate these common items into one config file and reference that from the various projects that need them?

Upvotes: 1

Views: 419

Answers (2)

user1228
user1228

Reputation:

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

Each project has a config file; these files get published to the bin directory as [output name].config (e.g., MyCode.DLL, MyCode.DLL.config). You can then reference these .config files from your main config (web.config).

If you find your config files aren't finding their way to the correct destination, you can do the post compilation step that ChanChan mentioned.

Upvotes: 1

DevelopingChris
DevelopingChris

Reputation: 40788

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

A few years back, this was the solution that was recommended by scott hanselman.

Upvotes: 1

Related Questions