【问题标题】:'IServiceCollection' does not contain a definition for 'AddSpaStaticFiles'“IServiceCollection”不包含“AddSpaStaticFiles”的定义
【发布时间】:2019-04-14 15:56:30
【问题描述】:

我无法弄清楚 Startup.cs 为何抛出此错误。我尝试了here 建议的解决方案(包括重新启动我的机器并运行 dotnet restore),但没有成功。有什么想法吗?

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

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

【问题讨论】:

  • 你能不能尝试包含来自 Nuget 的包:AutoMapper.Extensions.Microsoft.Dependencyinjection
  • @ErayBalkanli 我做了,它是我的 .csproj sn-p 中的第一个文件和我的 startup.cs 导入中的第 4 行

标签: c# asp.net


【解决方案1】:

你需要安装这两个 NuPackage:

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

【讨论】:

  • 那行得通 - 我通过 UI 安装它并收到错误“必须安装 Microsoft.CodeAnalysis”。一旦我这样做并按照上述步骤一切正常
猜你喜欢
  • 1970-01-01
  • 2019-06-09
  • 2022-01-03
  • 1970-01-01
  • 2020-04-02
  • 1970-01-01
  • 2016-09-25
  • 2020-08-20
  • 1970-01-01
相关资源
最近更新 更多