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;