现有10个程序他们的app.config几乎是一样的而且放在同一个文件下面,怎么样让这10个程序加载同一个app.config
解决方案
5
那你可以单独做个读取配置信息的项目,暴露方法。
15
可以指定要读取的文件名
/// <summary> /// 读取 XML 格式配置文件具体代码 /// </summary> public static void LoadSetting() { ExeConfigurationFileMap file = new ExeConfigurationFileMap(); file.ExeConfigFilename = "xxx.config"; Configuration cfg = ConfigurationManager.OpenMappedExeConfiguration(file, ConfigurationUserLevel.None); ConnectionStringSettings s = cfg.ConnectionStrings.ConnectionStrings["db"]; providername = s.ProviderName; connectionstring = s.ConnectionString; wsurl = cfg.AppSettings.Settings["wsurl"].Value; ftppath = cfg.AppSettings.Settings["ftppath"].Value; port = int.Parse(cfg.AppSettings.Settings["ftpport"].Value); uid = cfg.AppSettings.Settings["ftpuid"].Value; pwd = cfg.AppSettings.Settings["ftppwd"].Value; }