How do I disable all Roslyn Code Analyzers?
Asked Answered
M

9

53

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?
Mulch answered 6/4, 2016 at 19:58 Comment(0)
T
14

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

Towline answered 26/4, 2016 at 13:27 Comment(6)
@JoshVarty, I have installed Update 2 but nothing is available there.Torchwood
It's a checkbox in the Editor Helper group.Towline
@rolls It does work. Read here to understand what the checkbox is for.Loomis
Yes but the service is still present and using CPU. So what does that mean?Prophylactic
my firewall pops up and shows that RoslynCodeAnalysisService32 is trying to connect to internet, even when full solution analysis is not checked!Northwards
This doesn't work with the new Roslyn Analysers NuGet packageDisengage
S
28

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" />
...
Selfsame answered 6/4, 2016 at 20:30 Comment(4)
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?Mulch
I hope there's a way to manage analyzers on a scale of the entire solution. Maybe someone will pitch in.Selfsame
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 repoSelfsame
This doesn't actually stop the CPU usage though.Prophylactic
T
14

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

Towline answered 26/4, 2016 at 13:27 Comment(6)
@JoshVarty, I have installed Update 2 but nothing is available there.Torchwood
It's a checkbox in the Editor Helper group.Towline
@rolls It does work. Read here to understand what the checkbox is for.Loomis
Yes but the service is still present and using CPU. So what does that mean?Prophylactic
my firewall pops up and shows that RoslynCodeAnalysisService32 is trying to connect to internet, even when full solution analysis is not checked!Northwards
This doesn't work with the new Roslyn Analysers NuGet packageDisengage
B
13

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

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

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

Bone answered 22/10, 2019 at 3:8 Comment(1)
This only applies to .net framwork projects.Uppercut
R
10

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

Refulgent answered 19/5, 2021 at 6:5 Comment(1)
Sorry for the late posting but this is completely incorrect. This option does not disable code analysis at all. It controls where the code analysis is done. If it is enabled then the analysis will be done in another 64-bit process and the results will be passed to VS process via inter process communication. If the setting is enabled then the analysis will be done in the same process. Some extra info from the VS team can be found here: github.com/dotnet/roslyn-sdk/issues/515Azine
F
8

As of Visual Studio 2022: Tools > Options > Text Editor > C# > Advanced

enter image description here

Filature answered 18/5, 2022 at 8:12 Comment(1)
this was the only thing that worked for me. I had set the analysis attributes to 'false' in all of my .csproj files - but the Code Analysis was still taking up CPUBerkshire
M
6

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.

Moynihan answered 13/4, 2017 at 14:44 Comment(1)
This doesn't actually stop the CPU usage though.Prophylactic
L
6

In Visual studio 2022 i've resolved with disabled this two check:

  • enable 'pull' diagnostic(experimental,requires restart)
  • Run code analysis in separate process(requires restart)

enter image description here

Before Roslyn eating a lot of ram, after that visual studio work well.

Literacy answered 13/7, 2022 at 14:15 Comment(0)
B
5

One can place .editorconfig file to a folder for which (and its subfolders) one want to turn off all .NET analyzer warnings:

root = true

[*.cs]

# Disable all .NET analyzers
dotnet_analyzer_diagnostic.severity = none
dotnet_diagnostic.severity = none 

This is useful if one has an external library copy in a codebase and one does not want to modify its source code.

Barrack answered 30/3, 2022 at 13:55 Comment(2)
does it just stop the Warning/Notifications or also STOP the analyzers which eat the CPU/RAM?Northwards
I think it stops the analyzers. Asking the question here github.com/dotnet/roslyn/discussions would get you a definitive answer.Barrack
U
0

It's also possible to conditionally refer to a standalone analyzer package as in Conditionally Including a NuGet Package, PackageReference condition is ignored, Conditional package reference in UWP project

so just enable some analyzer when the build configuation to set to Debug(or any other you may create custom), and continue coding under the Release configuration without these analyzers:

    <Choose>
        <When Condition="'$(Configuration)' == 'Debug'">
            <ItemGroup>
                <PackageReference Include="..." Version="..." ExcludeAssets="compile" />
            </ItemGroup>
        </When>
    </Choose>

And that ExcludeAssets="compile" is as same as:

<PackageReference Include="..." Version="...">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime;build;native;contentfiles;analyzers;...</IncludeAssets>
</PackageReference>
Uppercut answered 21/11, 2023 at 21:45 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.