简体   繁体   中英

single config setting file in a solution c#

I have multiple projects in a solution. Each project has its own app.config file. I want to have a single app.config or settings file which can be used across the solution. What I see is now, when i want to add some settings common to the application I will have to add an entry it in all the projects app.config file.

I want to have a single configurable file (XML) which can be used in whole application. At run time if the value of any key is changed, my application should be able to get that changed value from the XML.

It's a arquiteture problem. Why you can't have a unique webconfig file. Everytime that you need to update an application, will have to update all. I think It's wrong.

You can to try a solution bellow:

  1. The best and correct option. Uses one commom Redis Cache. Everybody can call it.

  2. Save the configuration in one commom database table. So will have only one update in the solutions changes.

  3. Use a noSql(mongodb, cosmosdb etc.) database. It's faster then sql.

  4. Use one WebAPI. You can consult the configurations and to caching the information in each service.

obs: But if you whant a file. Can put in the solution and create a command to copy and replace the config when to build the solution. Like this:

Copying Visual Studio project file(s) to output directory during build

flw

You can use a linked file for using the same file in multiple projects in the same solution. This is good for using in multiple test projects that run either locally or from a build machine, however, for production code a centralized configuration would be a better approach.

For linking a file via the "Add Existing Item" select the arrow on the "Add" button and then choose "Add As Link".

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