读取当前配置文件的方法

it2022-05-08  14

var config = ConfigurationManager.OpenExeConfiguration(Assembly.GetAssembly(typeof(ProjectInstaller)).Location); this.serviceInstaller1.ServiceName = config.AppSettings.Settings["ServiceName"].Value;

我发现在有些情况下读取应用程序的配置文件会出现ConfigurationManager.AppSettings读取不到的情况,而用上面的代码却可以。比如Windows Service 的Installer里面动态从配置文件读取ServiceName的时候。

转载于:https://www.cnblogs.com/nanfei/archive/2012/11/08/2760725.html


最新回复(0)