Visual studion 2013 MVC5 (读取可移植类库的 app.config 值时出错)

本文关键字:config app 出错 类库 2013 studion MVC5 可移植 读取 Visual | 更新日期: 2023-09-27 18:36:27

Visual studion 2013 MVC5 (读取可移植类库的 app.config 值时出错)。我有两个项目

  1. 网络应用程序
  2. 可移植类库。

我在我想要的类库项目的 app.config 中使用了键值读取我的类文件,但由于系统配置类在库项目中不可用,所以我无法从 app.config 读取值:

<appSettings>
   <add key="xyz" value="123" />
</appSettings>

当我尝试读取类库的一个类文件中的值时,作为

public class mytest
{
  public static string AppValue=
      System.Configuration.ConfigurationManager.AppSettings["xyz"].ToString();
}

当我尝试使用System.Configuration时,我The 'configuration' element is not declared时收到错误,我在类库中没有得到这个。

Visual studion 2013 MVC5 (读取可移植类库的 app.config 值时出错)

请确保您的 web 配置文件中提供以下配置

<appSettings>
   <add key="xyz" value="123" />
</appSettings>