Windows 服务安装程序未读取 App.Config 文件 [英] Windows service installer not reading App.Config file

查看:42
本文介绍了Windows 服务安装程序未读取 App.Config 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中添加了 App.Config.我有一个安装程序类(ProjectInstaller.cs),它需要从 App.config 读取值.我提供钥匙.以下是示例代码:

I have added App.Config in my project. I have a installer class(ProjectInstaller.cs) which needs to read values from App.config. I am providing the keys . Below is the sample Code :

ConfigurationManager.AppSettings["CONFIG_FILE"]

当在安装程序类中调用时,我按照上面的代码得到空值.但在 App.Config 文件中,上述键的值存在.

I am getting null values as per above code ,when invoked in Installer class. But in App.Config file the value for the above key exists.

推荐答案

尝试:

public string GetServiceNameAppConfig(string serviceName)
{
    var config = ConfigurationManager.OpenExeConfiguration(Assembly.GetAssembly(typeof(MyServiceInstaller)).Location);
    return config.AppSettings.Settings[serviceName].Value;
}

这篇关于Windows 服务安装程序未读取 App.Config 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆