gpt4 book ai didi

c# - 从.NET Core 2.1降级到.NET 4.7.1时如何使用IApplicationBuilder和IServiceCollection?

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

我必须将我的项目从 .NET Core 2.1 更改为 .NET 4.7.1,并且修复了几乎所有错误,除了以下仍然无法解决的错误

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

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

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

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

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

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

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

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

我正在使用 Microsoft.AspNetCore.BuilderMicrosoft.Extensions.DependencyInjection。我还需要使用/安装/添加什么才能使 IApplicationBuilderIServiceCollection 正常工作?

在我的 WebApi.csproj 文件中,我将目标框架从 netcoreapp2.1 更改为 net471。

旧:

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

新:

<PropertyGroup>
<TargetFramework>net471</TargetFramework>
</PropertyGroup>

最佳答案

按照 Rik 的回答,我搜索了更多包,发现我必须添加以下所有 NuGet 包:

  • Microsoft.AspNetCore.Authentication
  • Microsoft.AspNetCore.Session
  • Microsoft.AspNetCore.HttpsPolicy
  • Microsoft.AspNetCore.CookiePolicy
  • Microsoft.AspNetCore.StaticFiles

执行此操作后,我不再收到错误消息。

关于c# - 从.NET Core 2.1降级到.NET 4.7.1时如何使用IApplicationBuilder和IServiceCollection?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51553024/

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