请查看https://github.com/dotnet/aspnetcore/issues/14723
仅用于测试目的,在项目文件中禁用分析器。
<PropertyGroup> <DisableImplicitAspNetCoreAnalyzers>true</DisableImplicitAspNetCoreAnalyzers>
</PropertyGroup>
禁用后,请检查是否仍然可以构建项目。检查是否存在先前版本依赖的任何安装包。
我一直在使用Microsoft.AspNetCore.MVC包来访问HttpContextAccessor,这导致了警告。
我通过重新安装HttpContextAccesstor的依赖/引用来解决这个问题,并且它将我带到了这个包中:
Microsoft.AspNetCore.Http.Abstractions
问题已解决。
<NoWarn>AD0001</NoWarn>
在我的情况下,原因是路由映射的方式。
// I use this because it's cleaner and the GetAllTodo function has DI parameters
app.MapGet("/manage/todos", GetAllTodo);
// but the following does not raise AD0001
app.MapGet("/manage/todos", () => GetAllTodo());