读取当前配置文件的方法

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

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

posted on 2012-11-08 17:12  空明流光  阅读(295)  评论(1编辑  收藏  举报

导航