【问题标题】:How to solve type or namespace name 'ConfigurationManager' does not exist in the namespace 'System.Configuration' error in .net standard?如何解决 .net 标准中的命名空间“System.Configuration”错误中不存在类型或命名空间名称“ConfigurationManager”?
【发布时间】:2020-10-31 18:35:48
【问题描述】:

我有一个 .net 框架类库项目,它与 .net 框架项目完全兼容,现在我还需要在 .net 核心应用程序中引用它。所以我正在尝试创建一个新的 .net 标准项目并将所有 .cs 文件从现有项目复制到该项目。并开始修复编译错误。我已经修复了很多,但仍然有一些。

string applicationName = System.Configuration.ConfigurationManager.AppSettings["Application"];

在上面一行,它给出了以下错误。

类型或命名空间名称“ConfigurationManager”不存在于 命名空间'System.Configuration'

目前尝试过:

  1. 我已添加包System.Configuration.ConfigurationManager 来自 Nuget
  2. 尝试从参考管理器添加System.Configuration.dll,但 它没有显示 System.Configuration.dll

.net 标准类库中如何解决这个问题?还是根本不支持?

另外,问题可能是如何在.net标准类库中读取appsettings.json文件?

【问题讨论】:

    标签: c# .net .net-core .net-standard .net-standard-2.1


    【解决方案1】:

    我通过从 NuGet 包管理器将 Microsoft.Extensions.Configuration 添加到项目中解决了这个问题。

    【讨论】:

    • 哇,我不知道他们把它做成了一个 nuget 包。太酷了,我以为他们只是弃用了 System.Configuration.ConfigurationManager。
    【解决方案2】:

    我在 Visual Studio 2019 中遇到了同样的问题。

    这帮助我解决了这个问题:

    右键单击项目并转到管理 NuGet 包。

    搜索 System.Configuraion 并安装 System.Configuration.ConfigurationManager

    现在在您的代码中,配置管理器将被识别。

    【讨论】:

    • 是 .net 标准项目吗?
    • @viveknuna 只是一个 c# 控制台应用程序。
    • 那么这不是这个问题的答案。问题是针对 .net 标准的
    猜你喜欢
    • 2012-12-06
    • 2012-12-01
    • 1970-01-01
    • 2021-03-15
    • 1970-01-01
    • 2013-05-24
    • 1970-01-01
    • 2012-06-19
    • 1970-01-01
    相关资源
    最近更新 更多