single app.config multi-project c#

ala picture ala · Sep 1, 2009 · Viewed 61.4k times · Source

I want to use a single app.config by 3 different projects.

How to access the configurations?

ConfigurationManager.AppSettings["config1"]

Answer

Jon Grant picture Jon Grant · Sep 1, 2009

Let's say you have this folder structure:

  • Solution
    • Project1
    • Project2
    • Project3

Do this:

  1. Create the App.config file in the Solution level folder. You won't find an option to add an App.config file from the templates, so just create a new empty text file with the name App.config, and paste in the contents of a regular App.config file.
  2. For each project in Solution Explorer:

    1. Right click and select Add > Existing Item
    2. Locate the file
    3. Select Add as link from the drop down box next to the Add button.

      Add as link

Edited to add:

You correctly state that the above method only shared the file up to build-time. To use a shared file at run-time, see the answers to this question.