Reputation: 8302
We have many C# console apps that run on scheduled tasks. All of these apps have their own config file, which contain settings like our smtp server. If our smtp server ever changed, we would have to manually go into each config file and change it. Can multiple apps look at 1 config file on the C: drive, or is that considered bad practice? Using the database to store values is a no no.
Upvotes: 6
Views: 5221
Reputation: 25732
You can point to external config files inside your application's configuration file like the following, and have all your applications use the same set of settings from a single file:
<appSettings file="c:\CommonSettings.config">
<add key="MyKey" value="12"/>
</appSettings>
For more information, you can read following articles:
Upvotes: 17
Reputation: 6322
Using Cinchoo framework you can achieve this, by simply creating custom configuration object and use it all the console applications. All of them will read from same configuration file. For more information, please visit http://www.cinchoo.com
Upvotes: 0
Reputation: 6862
Can you use custom xml files to store configuration data ? There's no necessity to use app.config.
Upvotes: 2
Reputation: 498904
It is not directly possible to share one application configuration file because the .config
filename needs to match the executable name (so for example.exe
it would be example.exe.config
).
It makes sense to have separate values for the different applications, as they are separate applications.
If there are configuration sections that you do want to share, you can use the configSource
attribute to point to a file. The appSettings
section also has a specific file
attribute that you can use in the same manner.
If there are certain configuration values that are shared across all applications, you can consider placing them in the machine.config
file for the version of the framework you are using.
Upvotes: 3