Net6升级到net8后Microsoft.AspNetCore.Http.Abstractions被弃用, IHttpContextAccessor新的调用方法

卸载后导致 IHttpContextAccessor无法使用,需要添加平台框架引用

参考以下方法解决

复制代码
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <NoWarn>1701;1702;8618;</NoWarn>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <NoWarn>1701;1702;8618;</NoWarn>
  </PropertyGroup>

  <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.5" /> <FrameworkReference Include="Microsoft.AspNetCore.App" /> </ItemGroup> </Project>
复制代码

csproj文件中加入

<FrameworkReference Include="Microsoft.AspNetCore.App" />

新的 IHttpContextAccessor来自命名空间
using Microsoft.AspNetCore.Http;
posted @ 2024-05-27 17:33  鹅是码农  阅读(357)  评论(0编辑  收藏  举报