question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Document build customization to disable analyzers when building in Visual Studio

See original GitHub issue

Some users are interested in disabling analyzers in Visual Studio to improve build performance. Specifically:

  • Enable analyzers for IntelliSense purposes
  • Enable analyzers for command line builds
  • Disable analyzers when actually building the project inside of Visual Studio

The documentation for this functionality should be preceded by a clear notice regarding the potential downside of this behavior.

⚠️ Using this build customization may change the build behavior in ways that increase the chances of developers submitting code which does not compile in the automated build environment. In particular, projects with any of the following characteristics are advised to avoid the use of this:

  • Projects with /warnaserror enabled
  • Projects with one or more analyzers installed that have a default severity of Error
  • Projects which use a rule set file to set the severity of one or more analyzers to Error

This can be accomplished by adding the following to a project file:

<Target Name="DisableAnalyzersForVisualStudioBuild"
        BeforeTargets="CoreCompile"
        Condition="'$(BuildingInsideVisualStudio)' == 'True' And '$(BuildingProject)' == 'True'">
  <!--
    Disable analyzers when building a project inside Visual Studio. Note that analyzer behavior for IntelliSense
    purposes is not altered by this.
  -->
  <ItemGroup>
    <Analyzer Remove="@(Analyzer)"/>
  </ItemGroup>
</Target>

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:9
  • Comments:21 (10 by maintainers)

github_iconTop GitHub Comments

3reactions
sharwellcommented, Nov 19, 2019

@SeidChr I’m not sure which version of the compiler tools first supports it, but you can pass /p:RunAnalyzersDuringBuild=false to the build to turn them off for the command line.

1reaction
springy76commented, Dec 21, 2021

@sharwell regarding your OP

<Analyzer Remove="@(Analyzer)"/>

Of course some of my colleges adopted your code years ago to shorten CI-build logs (too much stylecop warnings) and this week I’ve spent hours of googling and analyzing why after switching to net6 all CI-builds don’t have working razor pages (but everything else like static content, swagger, API works) - effectively this special project only has 1 razor page with dev info which isn’t essential for the app but I still wondered why it is missing now.

Guess what, I think you already know: Since NET5 there are more kinds of “Analyzers” which are faaaaaaaar moooooooore than just a simple analyzer - but some poor design(er) mixed them up being exactly at the same position:

  • System.Text.Json.SourceGeneration
  • Microsoft.Extensions.Logging.Generators

and finally starting with NET6

  • Microsoft.NET.Sdk.Razor.SourceGenerators

So my “analyzers” node in VS today consists of 7 real analyzers and 4 source generators, 9 of them default in a aspnet project +2 of stylecop. The word “generator” or “analyzer” at end of line, many times I have to scroll to see which one is which: Frustrating.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Disable source code analysis for .NET - Visual Studio
To disable source analysis at build time, uncheck the Run on build option. To disable live source analysis, uncheck the Run on live...
Read more >
How do you disable Roslyn Analyzers when using msbuild ...
Disable analyzers via an MSBuild property settable on the command line ... https://learn.microsoft.com/en-us/visualstudio/msbuild/customize- ...
Read more >
Disable legacy code analysis - Visual Studio (Windows)
In Solution Explorer, select and hold (or right-click) the project, and then select Properties. · In the properties dialog box for the project, ......
Read more >
Analyzer configuration - Visual Studio (Windows)
Learn how to customize Roslyn analyzer rules. See how to adjust analyzer severities, suppress violations, and designate files as generated ...
Read more >
Configure code inspection settings - ReSharper
You can recognize files where code inspection is disabled by the pause icon Code analysis paused on the status indicator.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found