Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

single app.config multi-project c#

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

How to access the configurations?

ConfigurationManager.AppSettings["config1"]
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...