“ IServiceCollection”不包含“ AddSpaStaticFiles”的定义 - c#

我不知道为什么Startup.cs引发此错误。我尝试了建议的here解决方案(包括重新启动计算机并运行dotnet restore),但没有成功。有任何想法吗?

CS1061'IServiceCollection'不包含'AddSpaStaticFiles'的定义,并且找不到可以接受的扩展方法'AddSpaStaticFiles'接受类型为'IServiceCollection'的第一个参数(您是否缺少using指令或程序集引用?)

“ IServiceCollection”不包含“ AddSpaStaticFiles”的定义 - c#

在startup.cs顶部使用语句:

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Myproject.Models;

using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens;
using System.Text;
//Install-Package Microsoft.AspNetCore.Session
//Install-Package AutoMapper.Extensions.Microsoft.DependencyInjection

我的.csproj文件包含:

  <ItemGroup>
    <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="5.0.1" />
    <PackageReference Include="Microsoft.AspNetCore.Session" Version="2.1.1" />
    <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.2.4" />
    <PackageReference Include="Flurl.Http" Version="2.2.1" />
    <PackageReference Include="jQuery" Version="3.3.1" />
    <PackageReference Include="jQuery.Validation" Version="1.17.0" />
    <PackageReference Include="LeanKit.API.Client" Version="1.2.6" />
    <PackageReference Include="Newtonsoft.Json" Version="11.0.2" />

    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.5" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.2" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.2" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.1.0-preview1-final" />
  </ItemGroup>

参考方案

您需要安装以下两个NuPackage:

“ IServiceCollection”不包含“ AddSpaStaticFiles”的定义 - c#

我们可以看到这是Microsoft.AspNetCore.SpaServices.Extensions程序集的扩展方法

“ IServiceCollection”不包含“ AddSpaStaticFiles”的定义 - c#

“ c#运算符是否就像Java中的instanceof一样?” - c#

我刚刚发现了这个运算符,我想知道它是否可以安全使用。我的意思是,在Java中,我们的老师总是告诉我们要避免使用instanceof(),因为它会破坏多态性并经常显示不良的编码。提前。 c#参考方案 它是安全的'。至少使用此检查更为安全,而不仅仅是强制转换并假定类型!您可能更喜欢使用as运算符,该运算符将转换为所需的类型(如果适用),否则返回null。只记得检…

当回复有时是一个对象有时是一个数组时,如何在使用改造时解析JSON回复? - java

我正在使用Retrofit来获取JSON答复。这是我实施的一部分-@GET("/api/report/list") Observable<Bills> listBill(@Query("employee_id") String employeeID); 而条例草案类是-public static class…

Div单击与单选按钮相同吗? - php

有没有一种方法可以使div上的click事件与表单环境中的单选按钮相同?我只希望下面的div提交值,单选按钮很丑代码输出如下:<input id="radio-2011-06-08" value="2011-06-08" type="radio" name="radio_date&#…

将python scikit学习模型导出到pmml - python

我想将python scikit-learn模型导出到PMML。哪个python软件包最合适?我阅读了有关Augustus的内容,但是我无法使用scikit-learn模型找到任何示例。 python大神给出的解决方案 SkLearn2PMML是 JPMML-SkLearn命令行应用程序周围的薄包装。有关受支持的Scikit-Learn Estimator和…

如何使HtmlGenericControl属性runat =“ server”。以从代码访问它? - c#

访问运行时创建的某些HtmlGenericControl时,我遇到一个奇怪的问题。如何制作HtmlGenericControl runat ="server"?以便我可以访问它 HtmlGenericControl myli = new HtmlGenericControl("li"); c#参考方案 正确,因为run…