Some projects' dependencies contain unexplained code analyzers

t3c*_*b0t 5 c# projects-and-solutions roslyn-code-analysis

I have a couple of projects where under Dependencies there are one or two branches of code analyzers like this:

在此处输入图片说明

I tried the right mouse click on every branch as explaind here but there is no option to configure them and I also searched for *.ruleset files insinde the solution, I also check the packages as shown in the docs but there is nothing like that anywhere.

There is also nothing suspicious in the .csproj files, just some nuget packages that I've installed but nothing analyzer related.

How do I get rid of them? They give me warnings when I reference such projects in other solutions and nuget restore doesn't fix it either:

在此处输入图片说明

I have no idea where they come from. Some projects have them and others don't. However, they seem to somehow be related to ASP.NET Core or MVC packages that are installed in those projects.

Mar*_*tti 5

Visual Studio 中存在一个错误,预计很快就会修复。当 Visual Studio 加载解决方案的所有项目并尝试解析所有依赖项以在解决方案资源管理器中显示时,某些依赖项可能会失败并显示为警告,并显示依赖项的可能文件的路径。

解决方法:

右键单击带有警告的项目,然后Unload Project在菜单中选择 。然后再次右键单击它并选择Reload Project。由于 Visual Studio 的后台进程不像加载整个解决方案的所有内容时那么繁忙,因此它很可能会解决依赖性。它似乎总是对我有用。


t3c*_*b0t 4

我通过删除文件夹microsoft.codeanalysis.analyzers并执行nuget restore. 它们仍然在下面Dependencies,但至少感叹号消失了。

我还通过向每个包添加<ExcludeAssets>analyzers</ExcludeAssets> 指令来删除分析器AspNetCore

<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.3">
  <ExcludeAssets>analyzers</ExcludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.1.1" >
  <ExcludeAssets>analyzers</ExcludeAssets>
</PackageReference>
Run Code Online (Sandbox Code Playgroud)

现在他们终于走了。

  • @mason 我只修复了最后两条抱怨 anlazyers 的黄线。第一个屏幕截图的结果仍然存在。你很容易说我应该解决实际问题。这些分析器的行为与“文档”中描述的不同。它们不可点击,不会向您显示据称无效的代码,它们不可配置,并且在“属性”窗口中读取它们确实很烦人,因为您看不到任何内容。我会继续忽略它们,因为它们没有帮助。我什至不知道他们为什么会在那里!:-o (4认同)