多个C#应用程序可以使用一个App.config文件? [英] Can multiple C# apps use one App.Config file?

查看:531
本文介绍了多个C#应用程序可以使用一个App.config文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个计划任务运行多个C#控制台应用程序。所有这些应用程序都有自己的配置文件,其中包括像我们的SMTP服务器设置。如果我们的SMTP服务器不断改变,我们就必须手动去到每一个配置文件,并改变它。多个应用程序可以看看1的配置文件位于C:驱动器,或者是认为不好的做法?使用数据库来存储的值是一个没有没有。

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.

推荐答案

您可以指向外部配置文件,如下面的应用程序的配置文件中,并把所有的应用程序都使用同一套设置从单个文件:

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:

  • AppSettings can Reference an External Config File
  • How to share custom application configuration settings across projects in .NET

这篇关于多个C#应用程序可以使用一个App.config文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆