从类库项目中的App.config中读取
我正在开发一个简单的类库项目,该项目将为我提供一个dll。
I am developing a simple class library project, which will give me a dll.
我希望从中读取特定的值配置文件。因此,我已经在项目中添加了一个App.config文件。
I wanted a particular value to be read from a config file. So I have added an App.config file to my project.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="serviceUrl" value="test value" />
</appSettings>
</configuration>
上面是我的App.config文件,现在我尝试按以下方式阅读
Above is my App.config file, and now I am trying to read it as following
string strVal = System.Configuration.ConfigurationManager.AppSettings["serviceUrl"];
但是我的字符串变量没有任何值。
But I am not getting any value in my string variable.
我已经以类似的方式对Web应用程序执行了此操作,并且它起作用了。
但是以某种方式我无法使它正常工作。
I had done this for a web application in a similar way and it worked. But somehow I am not able to get this working.
首先在类库项目中拥有App.config的想法是正确的吗? / p>
Is the idea of having App.config in a class library project correct in the first place ?
如我的评论所述,将App.Config文件添加到主要解决方案中,而不要添加到类库项目中。
As stated in my comment, add the App.Config file to the main solution and not in the class library project.