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


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


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

在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:

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

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

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

关于c# - “IServiceCollection”不包含“AddSpaStaticFiles”的定义,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53253526/

10-15 21:00