How do I disable all Roslyn Code Analyzers?

41,201

Solution 1

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

Solution 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

screenshot with the location of Open Active Rule Set

You can disable individual analyzers or entire bundles of analyzers.

checkboxes to disable 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" />
...

Solution 3

Disable below setting in Tools/Options/Text Editor/C#/Advanced and disable use 64-bit process for code analysis under analysis group. it was tested in vs2019.

enter image description here

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

Solution 5

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.

Share:
41,201
JoshVarty
Author by

JoshVarty

My blog.

Updated on July 01, 2021

Comments

  • JoshVarty
    JoshVarty almost 3 years

    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?
  • JoshVarty
    JoshVarty about 8 years
    The issue here is that there are hundreds of projects in the solution so I was hoping I wouldn't have to disable them one-by-one. They're also under source control I don't control, so when I pull I believe my changes will be overwritten, right?
  • Amadeusz Wieczorek
    Amadeusz Wieczorek about 8 years
    I hope there's a way to manage analyzers on a scale of the entire solution. Maybe someone will pitch in.
  • Amadeusz Wieczorek
    Amadeusz Wieczorek about 8 years
    To go around the source control issues, create a default .ruleset file (so that .csproj is updated) and commit these changes. Then, apply your configuration and follow this guide to keep changes out of git repo
  • Maxim
    Maxim almost 8 years
    @JoshVarty, I have installed Update 2 but nothing is available there.
  • Tamas
    Tamas almost 8 years
    It's a checkbox in the Editor Helper group.
  • HappyNomad
    HappyNomad almost 7 years
    @rolls It does work. Read here to understand what the checkbox is for.
  • rollsch
    rollsch almost 7 years
    Yes but the service is still present and using CPU. So what does that mean?
  • S.Serpooshan
    S.Serpooshan over 6 years
    my firewall pops up and shows that RoslynCodeAnalysisService32 is trying to connect to internet, even when full solution analysis is not checked!
  • rollsch
    rollsch over 5 years
    This doesn't actually stop the CPU usage though.
  • rollsch
    rollsch over 5 years
    This doesn't actually stop the CPU usage though.
  • Christian Findlay
    Christian Findlay about 5 years
    This doesn't work with the new Roslyn Analysers NuGet package