在命名空间“System.Configuration"中找不到类型名称“ConfigurationManager".此类型已转发 [英] The type name 'ConfigurationManager' could not be found in the namespace 'System.Configuration'. This type has been forwarded

本文介绍了在命名空间“System.Configuration"中找不到类型名称“ConfigurationManager".此类型已转发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 Visual Studio 2019 的 .NET 5.0 项目中收到此错误(已在社区/学生版和专业版上试用).

I received this error in a .NET 5.0 project using Visual Studio 2019 (tried on Community/Student edition as well as Professional).

"在命名空间System.Configuration"中找不到类型名称ConfigurationManager".此类型已转发..."

我发现的许多答案都说您需要添加使用 System.Configuration;";以及通过 Project -> 添加程序集命名空间作为引用添加参考.这个答案没有对我有用,因为没有参考"文件夹或添加参考"的任何选项在项目选项卡中.也没有程序集"标签. 仅项目",共享项目",COM"和浏览".

Many of the answers I found said that you needed to add "using System.Configuration;" as well as add the assembly namespace as a reference through Project -> Add Reference. This answer did not work for me as there is no "References" folder or any option to "Add Reference" in the Project tab. There is also no "Assemblies" tab in the Reference Manager. Only "Projects," "Shared Projects," "COM," and "Browse."

如何添加 System.Configuration 作为参考以便我可以使用 ConfigurationManager?

How do I add System.Configuration as a reference so that I may use ConfigurationManager?

推荐答案

System.Configuration.ConfigurationManager is not supported in .NET 5. 有关如何将具有 web.config 文件的应用迁移到 .NET Core 的信息,请参阅此处模式 迁移配置

System.Configuration.ConfigurationManager is not supported in .NET 5. See here for how you would migrate an app with a web.config file to the .NET Core pattern Migration Configuration

虽然可以在 .NET 5 应用程序中使用 System.Configuration.Configuration 管理器,但这是一个坏主意.该框架已将新内容与应用程序启动集成在一起,如果您不使用它,您就会让自己做更多的工作.较新的配置模式更易于使用和部署到多个环境中.如果您有想要移植到 .NET 5 的现有 .NET 经典应用程序,请按照上面的文档进行操作.如果这是一个新应用程序,请查看 Microsoft.Extensions.Configuration 命名空间.

While it might be possible to use System.Configuration.Configuration manager in a .NET 5 application, it is a bad idea. The framework has integrated the new stuff with application startup and if you don't use it you are making yourself more work. The newer configuration patterns are easier to use and deploy into multiple environments. If you have an existing .NET classic app you want to port to .NET 5, follow that documentation from above. If this is a new application check out the Microsoft.Extensions.Configuration namespace.

这篇关于在命名空间“System.Configuration"中找不到类型名称“ConfigurationManager".此类型已转发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆