Windows服务安装不读App.config文件 [英] Windows service installer not reading App.Config file

查看:581
本文介绍了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天全站免登陆