55

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?

9 Answers 9

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" />
...
Sign up to request clarification or add additional context in comments.

4 Comments

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?
I hope there's a way to manage analyzers on a scale of the entire solution. Maybe someone will pitch in.
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
This doesn't actually stop the CPU usage though.
15

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

6 Comments

@JoshVarty, I have installed Update 2 but nothing is available there.
It's a checkbox in the Editor Helper group.
@rolls It does work. Read here to understand what the checkbox is for.
Yes but the service is still present and using CPU. So what does that mean?
my firewall pops up and shows that RoslynCodeAnalysisService32 is trying to connect to internet, even when full solution analysis is not checked!
|
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

1 Comment

This only applies to .net framwork projects.
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

1 Comment

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/515
9

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

enter image description here

1 Comment

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 CPU
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.

1 Comment

This doesn't actually stop the CPU usage though.
6

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.

2 Comments

does it just stop the Warning/Notifications or also STOP the analyzers which eat the CPU/RAM?
I think it stops the analyzers. Asking the question here github.com/dotnet/roslyn/discussions would get you a definitive answer.
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.

Comments

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.