简体   繁体   中英

Using one app.config file for multiple projects

I have a solution with the following setup:

X amount of class library projects Y amount of console application projects

Each of these projects may have 0 or more configuration parameters.

Now, I'd like to have only one App.config for user to specify settings and that App.config will only contain parameters of all the reference projects of the console application project to be run.

I've tried giving each project a Settings file and then linking them to the console applications according to their dependencies but that didn't work.

I've also tried just lumping all the configurations together in one class library project and have each console application link to that app.config (or settings file). But that also didn't work (ie changes of the app.config or the settings file in the class library will not update the .config of the executable)

Is what I am trying to do possible?

Yes, it is possible. You just need to open the app file. Follow the next example:

ConfigurationManager.OpenExeConfiguration("C:\Test\SomeProject.dll");
XmlNode loggingConfigNode = ConfigurationManager.GetSection("log4net") as XmlNode;

I guess that you will have to open each setting file in order to use the settings, or you will have to consolidate all the settings in a single app.config and then your applications can access the file by open it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM