无法从appSettings中读取 [英] Can't read from appSettings
问题描述
我有一个测试项目,该测试项目中包含一个web.config文件.当我尝试从web.config的appSettings部分读取值时,我一直得到null.
I have a test project with a web.config file in the test project. I keep getting null when I try to read a value from the appSettings section of the web.config.
我有对System.configuration的引用,并有一条using语句 using System.Configuration;
I have a reference to System.configuration and a using statement using System.Configuration;
<appSettings>
<add key="SatisfactionSurveyLink" value="Link"/>
</appSettings>
[TestMethod()]
public void TestReadFromAppSettings()
{
String surveyLink = ConfigurationManager.AppSettings["SatisfactionSurveyLink"];
Assert.IsNotNull(surveyLink);
}
我尝试了许多不同的操作,但无法正常工作.有人对问题可能有什么建议吗?
I've tried many different things and can't get this to work. Does anyone have any suggestions as to what the problem could be?
谢谢
罗纳德
推荐答案
如果它是作为类库创建的测试项目,则不需要web.config但需要app.config;-)
if it is a test project created as class library, does not need the web.config but the app.config ;-)
这篇关于无法从appSettings中读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!