single app.config multi-project c#

前端 未结 7 1937
清歌不尽
清歌不尽 2020-11-27 15:10

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

How to access the configurations?

ConfigurationManager.AppSettings[\"config1\"]

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 15:22

    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.

    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.

提交回复
热议问题