gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 14:47:26 25 4
gpt4 key购买 nike

我不明白为什么 Startup.cs 会抛出此错误。我尝试了建议的解决方案 here (包括重新启动我的机器并运行 dotnet Restore)但运气不佳。有什么想法吗?

CS1061 'IServiceCollection' does not contain a definition for 'AddSpaStaticFiles' and no accessible extension method 'AddSpaStaticFiles' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?)

enter image description here

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

最佳答案

您需要安装这两个NuPackages:

enter image description here

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

enter image description here

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com