.Net Tips — using configSource or file attribute to externalize config sections

There’s a lit­tle known attribute which was intro­duced in the .Net frame­work 2.0 called con­fig­Source, which allows you to exter­nal­ize sec­tions of the con­fig­u­ra­tion file.

It works just like the option­al file attribute found on the appSet­tings ele­ment:

<appSet­tings file = “rel­a­tive file name” />

but can be added to any con­fig­u­ra­tion sec­tion to spec­i­fy an exter­nal file for that sec­tion:

<Cus­tom­Sec­tion configSource=“relative file name” />

When it comes to WCF though, unfor­tu­nate­ly the con­fig­Source attribute doesn’t work on the <system.serviceModel> sec­tion group, but luck­i­ly you can still apply it on the child con­fig sec­tions. See the ref­er­ence link below for some exam­ples.