CS8032 突然发出 Microsoft.CodeAnalysis 警告
自从我们切换到.net6以来,我已经有了一个有很多项目的解决方案,然后我突然在Visual Studio中获得了每个项目,但是它没有出现在MSBUILD输出上,并且设置了分析仪。在构建上运行。如何追踪为什么会发生这种情况?分析仪被自动包含在我使用.NET6的NET SDK项目的一部分中,因此我不知道的Nuget软件包参考吗?
警告CS8032分析仪的实例 Microsoft.codeanalysis.csharp.analyzers.metaanalyzers.csharpreportdiagnosticanalyzer 不能用 c:\ users \ defaultuser \ .nuget \ packages \ microsoft.codeanalysis.analyzers \ 3.0.0 \ Analyzers \ dotnet \ dotnet \ cs \ microsoft.codeanalysis.csharp.analyzers.dll:不能加载类型类型类型 'Microsoft.codeanalysis.analyzers.metaanalyzers.reportdiagnosticanalyzer4' 从汇编'Microsoft.codeanalysis.analyzers,版本= 3.3.5.2003, 文化=中性,publicKeyToken = 31bf3856ad364e35'..
system.typeloadexception:无法加载类型 Microsoft.codeanalysis.analyzer.metaanalyzers.ReportDiagnosticanalyzer4 从汇编Microsoft.codeanalysis.analyzers,版本= 3.3.5.2003, 文化=中性,publicKeyToken = 31BF3856AD364E35。在 system.Reflection.runtimeassembly.getType(Runtimeassembly组装, 字符串名称,布尔特罗纳(Boolean Thronerror),布尔无ignorecase, ObjectHandLeonStack类型)at System.Reflection.Runtimeassembly.getType(字符串名称,布尔值 throwonError,布尔无ignorecase) Microsoft.codeanalysis.diagnostics.analyzerfilereference.extensions`1.getAnalyzersFortyPenames(组装 AnalyzerAssembly,Ienumerable1 AnalyzertyPenames,Boolean& 报告)
I've had a solution with a large number of projects in that has built fine since we switched to .NET6 then suddenly I am getting for every project this warning in Visual studio, however it does not appear on the MSBuild output and analyzers are set to run on build. Any idea of how to track down why this is happening? The analyzers are included automatically as part of the fact I am using NET SDK projects with .NET6 so there isn't Nuget package references in he way that I know of?
Warning CS8032 An instance of analyzer
Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpReportDiagnosticAnalyzer
cannot be created from
C:\Users\defaultuser\.nuget\packages\microsoft.codeanalysis.analyzers\3.0.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll: Could not load type
'Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.ReportDiagnosticAnalyzer4'
from assembly 'Microsoft.CodeAnalysis.Analyzers, Version=3.3.5.2003,
Culture=neutral, PublicKeyToken=31bf3856ad364e35'..
System.TypeLoadException: Could not load type
Microsoft.CodeAnalysis.Analyzers.MetaAnalyzers.ReportDiagnosticAnalyzer4
from assembly Microsoft.CodeAnalysis.Analyzers, Version=3.3.5.2003,
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, IEnumerable1 analyzerTypeNames, Boolean&
reportedError)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我有类似的问题。在 .net6 上运行,但对旧版本的 Microsoft.CodeAnalysis.CSharp 有传递性 nuget 依赖性。
在我的宿主项目中,手动添加 Microsoft.CodeAnalysis.CSharp 最新版本(撰写本文时为 4.4.0)即可解决问题。所有 CS8032 警告现已消失。
I had a similar problem. Running on .net6 but with a transitive nuget dependency on an older version of Microsoft.CodeAnalysis.CSharp.
On my host project, manually adding Microsoft.CodeAnalysis.CSharp latest version (4.4.0 at the time of this writing) did the trick. All CS8032 warnings are gone now.
在最新的 VS2022 上升级 .net 5-6 - 解决方案已经发展了近 10 年:
一个依赖于许多其他项目的项目仍在引用此 nuget 包:Microsoft.AspNetCore.Mvc v 2.2.0。
由于它是最新版本,因此并不需要更新,但已不再在任何地方使用。因此,到目前为止,它一直在雷达下飞行。
从该项目中删除这个 nuget 包就消除了我所有的 CS8032 警告。
Upgrading .net 5-6 on latest VS2022 - solution has been evolving for almost 10 years:
One project that is a dependency for many others was still referencing this nuget package: Microsoft.AspNetCore.Mvc v 2.2.0.
Since it's the most recent version, it didn't stand out as needing to be updated, however was no longer being used anywhere. So, it has flown under the radar, until now.
Removing this nuget package from that project eliminated all my CS8032 warnings.
由于Microsoft.aspnetcore.mvc,我也出现了一套类似的警告,并添加了对“ Microsoft.codeanalysis.analyzers”软件包的引用。
I had a similar set of warnings appear due to Microsoft.AspNetCore.Mvc, adding a reference to the "Microsoft.CodeAnalysis.Analyzers" package resolved it.
我的CSPROJ有一个包含Microsoft.visualstudio.web.codegeneration.design版本“ 6.0.2”的软件包引用。
如果您沿着兔子洞走下去,您会发现它具有 microsoft.dotnet.scaffolding.shared 的引用,该 ,它引用了 microsoft.codeanalysis.csharp 。
尝试删除包裹,看看它是否解决了您的问题。
My csproj had a package reference to Microsoft.VisualStudio.Web.CodeGeneration.Design Version "6.0.2".
If you go down the rabbit hole you will see that it has a reference to Microsoft.DotNet.Scaffolding.Shared which has a reference to Microsoft.CodeAnalysis.CSharp.
Try removing the package and see if it resolves your issue.
正如此处建议的那样,我尝试跟踪哪个依赖项导致冲突以更新它,并尝试使用显式引用覆盖它。
但最后发现问题是我的系统上安装了两个版本的 .NET SDK 6.0.x。 我删除了较新的版本,现在只安装了 6.0.302,问题就消失了。
可能有一种更优雅的方法来解决这个问题,请告诉我您是否知道。
As was advised here, I tried to track which dependency is causing the conflict to update it, and tried to override it with explicit reference.
But at the end what turned out to be the problem is that I had two versions of .NET SDK 6.0.x installed on my system. I removed the newer one, and now with only 6.0.302 installed, the problem is gone.
There is probably a more elegant way to solve this issue, tell me if you are aware of one.
当我将 Microsoft.AspNetCore.Html.Abstractions 包添加到不是网站本身的项目时,出现了问题。通过应用程序构建导致错误。
我试图将一些 HtmlHelper 扩展添加到库中。决定不值得。
删除包裹就清除了所有其他内容。
My issue happened when I added the Microsoft.AspNetCore.Html.Abstractions package to a project that was not the website itself. Caused the errors through the application build.
I was trying to add some HtmlHelper extensions into a library. Decided it wasn't worth it.
Removing the package cleared up everything else.