Today I just learned how to share same configuration file between multiple projects, There are two projects and I need to use same configuration file in both projects. Below code will do the same.
ExeConfigurationFileMap efm = new ExeConfigurationFileMap { ExeConfigFilename = "AppConfig/app.config" }; Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(efm, ConfigurationUserLevel.None); if (configuration.HasFile) { AppSettingsSection appSettings = configuration.AppSettings; KeyValueConfigurationElement element = appSettings.Settings["myconfig"]; Console.WriteLine(element.Value); Console.ReadKey(true); }
Published under: Microsoft .NET Tips · · · ·