Document build customization to disable analyzers when building in Visual Studio
See original GitHub issueSome 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:
- Created 8 years ago
- Reactions:9
- Comments:21 (10 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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.@sharwell regarding your OP
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:
and finally starting with NET6
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.