Breaking the itch/scratch cycle of managing multi project App.config files in c#

February 26, 2010

I’ve been meaning to get around to sorting out the plethora of App.config in a large, multi project C# solution, but it wasn’t anywhere near the top of the pile of problems that needed solving. I just keep hacking values into the *.exe.config file after the build to make things work.

In a spare (and rare) 20 minutes, while drinking a coffee, I thought I’d have a quick look and discovered a really simple solution. For some reason this technique had completely passed me by. Imagine you’ve got a C# solution made up of 3 projects which build into 3 separate executables, each requiring a common config file. If you have simply added a config file to each project and try to keep them in sync you quickly end up in config hell. So rather that add a new config file to each project, simply create one in one of the projects and then link it in the others.

Here’s how, in our imaginary 3 project solution


  • Right click on Project1 and select Add->New Item->Application Configuration File and it will create a the file App.config in Project1.
  • Right click on Project2 and select Add->Existing Item and browse to Project1’s App.config file, but don’t hit the Add button. Select the Add button drop down and select Add as link.
  • Repeat for Project3

So now when you open any of the projects App.config files you will be using the same file. More importantly, when you build the solution, each projects bin/Debug (Release) directory will have it’s own, but identical copy of the config file (Project*.exe.config) leaving you the freedom to deploy the executables with their own or a common config file. Essentially, building the solution duplicates the config files from a single master version.

Itch successfully scratched.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: