c# – Windows服务安装程序无法读取App.Config文件

前端之家收集整理的这篇文章主要介绍了c# – Windows服务安装程序无法读取App.Config文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在我的项目中添加了App.Config.
我有一个安装程序类(ProjectInstaller.cs),它需要从App.config中读取值.
我提供钥匙.
以下是示例代码
  1. ConfigurationManager.AppSettings["CONFIG_FILE"]

在Installer类中调用时,我按照上面的代码获取空值.
但是在App.Config文件中,存在上述键的值.

解决方法

尝试:
  1. public string GetServiceNameAppConfig(string serviceName)
  2. {
  3. var config = ConfigurationManager.OpenExeConfiguration(Assembly.GetAssembly(typeof(MyServiceInstaller)).Location);
  4. return config.AppSettings.Settings[serviceName].Value;
  5. }

猜你在找的C#相关文章