github上其實已經有這個問題的解決方案,有興趣的可以直接去看:
https://github.com/dotnet/aspnetcore/issues/14723
我的解決方案是基於.netcore 3.1,vs版本是vs2019 16.8.4;
產生這個問題的原因在於同時分析器中同時存在兩個版本的Microsoft.AspNetCore.Mvc.Analyzers
最終官方給出的解決方案是,在項目文件中增加這個配置:
<PropertyGroup>
<DisableImplicitAspNetCoreAnalyzers>true</DisableImplicitAspNetCoreAnalyzers> </PropertyGroup>
項目文件中如果有引用MVC2.2.0版本,記得移除掉
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />