Can multiple C # applications use the same App.Config file?

We have many C # console applications that run on scheduled tasks. All these applications have their own configuration file, which contains settings such as our smtp server. If our smtp server ever changed, we would have to manually go to each configuration file and change it. Can multiple applications look at 1 configuration file on a C: drive or is this considered bad practice? Using a database to store values ​​is not.

+5
source share
4 answers

You can specify external configuration files inside your application configuration file, as well as the following, and so that all your applications use the same set of parameters from one file:

<appSettings file="c:\CommonSettings.config"> <add key="MyKey" value="12"/> </appSettings> 

For more information, you can read the following articles:

+14
source

You cannot directly use one application configuration file, since the name of the .config file must match the name of the executable file (therefore, for example.exe it will be example.exe.config ).

It makes sense to have separate values ​​for different applications, since they are separate applications.

If there are configuration sections that you want to use, you can use the configSource attribute to point to the file. The appSettings section also has a special file attribute, which you can use in the same way.

If there are specific configuration values ​​that are common to all applications, you can put them in the machine.config for the version you are using.

+3
source

Can you use custom xml files to store configuration data? No need to use app.config.

+2
source

Using the Cinchoo framework, you can achieve this by simply creating your own configuration object and using all console applications. All of them will read from the same configuration file. For more information, visit http://www.cinchoo.com

0
source

All Articles