我有一个使用 .net standard 2.0 的 lib 项目。
我收到了 5 条警告,内容为无法加载以下类型:FixerWithFixAllAnalyzer
、DiagnosticAnalyzerFieldsAnalyzer
、DiagnosticDescriptorCreationAnalyzer
、CSharpRegisterActionAnalyzer
、ReportDiagnosticAnalyzer
示例:
Warning CS8032 An instance of analyzer Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpReportDiagnosticAnalyzer cannot be created from C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll: Could not load type 'Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.ReportDiagnosticAnalyzer`4' from assembly 'Microsoft.CodeAnalysis.Analyzers, Version=3.3.3.10305, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.. MyLib (netstandard2.0) C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll 1 Active System.TypeLoadException: Could not load type 'Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.ReportDiagnosticAnalyzer`4' from assembly 'Microsoft.CodeAnalysis.Analyzers, Version=3.3.3.10305, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
at System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type)
at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
at Microsoft.CodeAnalysis.Diagnostics.AnalyzerFileReference.Extensions`1.GetAnalyzersForTypeNames(Assembly analyzerAssembly, IEnumerable`1 analyzerTypeNames, Boolean& reportedError)
Severity Code Description Project File Line Suppression State Detail Description
Warning CS8032 An instance of analyzer Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpRegisterActionAnalyzer cannot be created from C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll: Method 'GetCodeBlockAnalyzer' in type 'Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpRegisterActionAnalyzer' from assembly 'Microsoft.CodeAnalysis.CSharp.Analyzers, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.. MyLib (netstandard2.0) C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll 1 Active System.TypeLoadException: Method 'GetCodeBlockAnalyzer' in type 'Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpRegisterActionAnalyzer' from assembly 'Microsoft.CodeAnalysis.CSharp.Analyzers, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.
at System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type)
at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
at Microsoft.CodeAnalysis.Diagnostics.AnalyzerFileReference.Extensions`1.GetAnalyzersForTypeNames(Assembly analyzerAssembly, IEnumerable`1 analyzerTypeNames, Boolean& reportedError)
使用 VS2022 17.4.4
尝试删除所有的 bin/obj
文件夹,并在重启后尝试。
更新: 为了隔离问题,我已经删除了项目中的所有文件。 在我的项目文件中,我有以下内容:
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
</ItemGroup>
当我将其移除时,警告消失了,但当它们存在时,我也可以在.netstandard2.0下看到一些MVC警告,我附上了截图:
VS2022 17.4.4
, 我相信这是最新版本。 - buga.netstandard
迁移?同时尝试删除ASP.NET Core包并添加FrameworkReference
- 参见此答案。 - Guru Stronnetstandard2.0
和netcoreapp3.1
的库; 关于你的解决方案,我得到了这个错误信息:未识别 FrameworkReference 'Microsoft.AspNetCore'
。 - buga