我在我的项目中添加了App.Config.
我有一个安装程序类(ProjectInstaller.cs),它需要从App.config中读取值.
我提供钥匙.
以下是示例代码:
我有一个安装程序类(ProjectInstaller.cs),它需要从App.config中读取值.
我提供钥匙.
以下是示例代码:
ConfigurationManager.AppSettings["CONfig_FILE"]
在Installer类中调用时,我按照上面的代码获取空值.
但是在App.Config文件中,存在上述键的值.
解决方法
尝试:
public string GetServiceNameAppConfig(string serviceName)
{
var config = ConfigurationManager.OpenExeConfiguration(Assembly.GetAssembly(typeof(MyServiceInstaller)).Location);
return config.AppSettings.Settings[serviceName].Value;
}