'ConfigurationBuilder'不包含'AddJsonFile'的定义 - c#

我有以下错误:

Program.cs(15,72):错误CS1061:“ ConfigurationBuilder”不包含“ AddJsonFile”的定义,并且找不到包含“ ConfigurationBuilder”类型的第一个参数的可访问扩展方法“ AddJsonFile”(您是否缺少使用指令或汇编

该项目是一个使用Azure Search SDK的dotnet核心应用程序,控制台应用程序

错误行如下:

using System;
using System.Linq;
using System.Threading;
using Microsoft.Azure.Search;
using Microsoft.Azure.Search.Models;
using Microsoft.Extensions.Configuration;
using Microsoft.Spatial;

namespace DemoSearchIndexer
{
    class Program
    {
        static void Main(string[] args)
        {
            IConfigurationBuilder builder = new ConfigurationBuilder().AddJsonFile("appsettings.json");
            IConfigurationRoot configuration = builder.Build();

参考方案

AddJsonFile扩展方法来自Microsoft.Extensions.Configuration.Json NuGet包。在构建通常引用Microsoft.AspNetCore.AllMicrosoft.AspNetCore.App的ASP.NET Core应用程序时,您可以免费获得该应用程序。

在构建控制台应用程序或至少不引用那些元软件包之一的应用程序时,您需要添加一个显式的PackageReference以获得扩展方法。

为什么使用'=='或'is'比较字符串有时会产生不同的结果? - python

我有一个Python程序,其中将两个变量设置为'public'值。在条件表达式中,我有比较var1 is var2失败,但如果将其更改为var1 == var2,它将返回True。现在,如果我打开Python解释器并进行相同的“是”比较,则此操作成功。>>> s1 = 'public' >>…

单行的'if'/'for'语句是否使用Python样式好? - python

我经常在这里看到某人的代码,看起来像是“单线”,这是一条单行语句,以传统的“if”语句或“for”循环的标准方式执行。我在Google周围搜索,无法真正找到可以执行的搜索类型?任何人都可以提出建议并最好举一些例子吗?例如,我可以一行执行此操作吗?example = "example" if "exam" in exam…

将字符串分配给numpy.zeros数组[重复] - python

This question already has answers here: Weird behaviour initializing a numpy array of string data                                                                    (4个答案)         …

TypeError:'str'对象不支持项目分配,带有json文件的python - python

以下是我的代码import json with open('johns.json', 'r') as q: l = q.read() data = json.loads(l) data['john'] = '{}' data['john']['use…

如何修复AttributeError:模块'numpy'没有属性'square' - python

Improve this question 我已经将numpy更新为1.14.0。我使用Windows10。我尝试运行我的代码,但出现此错误: AttributeError:模块“ numpy”没有属性“ square”这是我的进口商品:%matplotlib inline import matplotlib.pyplot as plt import ten…