c# - .NET 6.0 ConfigurationBuilder 缺少 AddJsonFile 方法

标签 c# .net-6.0

var builder = new ConfigurationBuilder().AddJsonFile(somepath);

错误消息状态

ConfigurationBuilder does not contain a definition for AddJSONFile.

如果我查看“依赖项/包”文件夹,则会显示以下内容:

Microsoft.Extensions.Configurations(6.0.1)

该类的此版本中似乎缺少方法。

最佳答案

安装Microsoft.Extensions.Configuration.Json nuget 包。

我还建议考虑Microsoft.Extensions.Hosting nuget 通过 generic hosting 处理了很多此类问题(并且取决于上述包):

A host is an object that encapsulates an app's resources and lifetime functionality, such as:

  • Dependency injection (DI)
  • Logging
  • Configuration
  • App shutdown
  • IHostedService implementations

关于c# - .NET 6.0 ConfigurationBuilder 缺少 AddJsonFile 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74127366/

相关文章:

reactjs - react + asp.net core (.net 6) 创建新 Controller

c# - EqualityComparerer<T>.Default.Equals() 与 object.Equals() 和多态性

c# - 使用 LINQ 重写代码

c# - 如何在 F# 中实现 C# 接口(interface)?

c# - .net6.0 上的 Azure Functions 无法在本地运行,并出现 hostpolicy.dll 错误

c# - 取消引用可能的空引用 C#

c# - 无法关闭 SHGetFileInfo

c# - Linq.Enumerable 中的索引越界

c# - 带 WinUI 3 的托盘图标

azure - .Net6 Azure Functions 中的 ILogger 依赖项注入(inject)问题