How do I disable all Roslyn Code Analyzers?

左心房为你撑大大i 提交于 2019-11-29 16:50:54

问题


I'm trying to work with a large opensource project that has a handful of Roslyn Code Analyzers. When I open the solution Visual Studio uses ~35% CPU for about 15 minutes. Using PerfView I've figured out that the code analyzers being run on the solution are bogging down Visual Studio.

I know it's possible to disable analyzers on a per-project basis but this solution contains over 100 projects so I'd rather not do this one-by-one.

My question(s):

  • Can I disable all Roslyn Analyzers for a given solution to avoid this?
  • Can I disable all Roslyn Analyzers for all solutions in Visual Studio?

回答1:


Try Tools/Options/Text Editor/C#/Advanced and disable full solution analysis. It's only available since VS2015 Update 2.




回答2:


You can disable analyzers on a per-project basis.

To do it, right click on Project>References>Analyzers in the Solution Explorer and hit Open Active Rule Set

You can disable individual analyzers or entire bundles of analyzers.

This creates a <ProjectName>.ruleset file and modifies the <ProjectName>.csproj, which means that you will share this configuration with your team unless you exclude these changes from source control.

Note: Changes are applied after you close and re-open the solution.


Changes to the .csproj:

<Project ...>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <CodeAnalysisRuleSet>Example.ruleset</CodeAnalysisRuleSet>

Example.ruleset file:

<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Rules for WpfApplication1" Description="Code analysis rules for WpfApplication1.csproj." ToolsVersion="14.0">
  <Rules AnalyzerId="Microsoft.CodeAnalysis.CSharp" RuleNamespace="Microsoft.CodeAnalysis.CSharp">
    <Rule Id="AD0001" Action="None" />
    <Rule Id="CS0028" Action="None" />
...



回答3:


It is possible to reference a ruleset file located in the parent folder

<Project ...>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <CodeAnalysisRuleSet>..\Example.ruleset</CodeAnalysisRuleSet>

This way you could define one ruleset for the entire solution.




回答4:


Try a combo of the following in your csproj or Directory.Build.props files

<RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild>
<RunAnalyzersDuringLiveAnalysis>false</RunAnalyzersDuringLiveAnalysis>
<RunAnalyzers>false</RunAnalyzers>

https://docs.microsoft.com/en-us/visualstudio/code-quality/disable-code-analysis?view=vs-2019#net-framework-projects



来源:https://stackoverflow.com/questions/36461174/how-do-i-disable-all-roslyn-code-analyzers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!