roslyn: IDE rules don't fail builds

When using code analysis with the IDE rules under Microsoft.CodeAnalysis.CSharp.Features enabled and their action set to Error, if one of the rules is violated, I correctly get the error message, however if I attempt to build the project, the build succeeds.

Is this the intended behavior of these IDE rules? It seems very unintuitive to see 2 Errors and Build Succeeded at the same time.

Steps to reproduce:

  1. New Console Application
  2. Navigate to Project -> Properties -> Code Analysis
  3. Check Enable Code Analysis on Build
  4. Open the rule set
  5. Uncheck Managed Binary Analysis and Microsoft.CodeAnalysis.CSharp
  6. Change Action of Microsoft.CodeAnalysis.CSharp.Features to Error and ensure Microsoft.CodeAnalysis.CSharp.Features is checked
  7. Save the edited ruleset (should be saved as {name of project}.ruleset)
  8. Build project

Observe 2 Errors, 1 Warning in Error List but 0 error(s), 1 warning(s) in output window.

What’s even stranger is the error locations take me to a temporary file located at %tmp%\.NETFramework,Version=v4.6.AssemblyAttributes.cs. Should this even be analyzed?

This isn’t the issue however, if I put the following in Main:

System.String test = "ABC";

I correctly get the error squiggle and error in the errors window, however the build still succeeds.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 5
  • Comments: 20 (9 by maintainers)

Most upvoted comments

Is there a Roslyn analyzer nuget package that analyze IDExxx stuff?

Okay - for my money this isn’t broken at all! It’s just not obvious how to do things. See conversation here: https://github.com/dotnet/roslyn/issues/60620

And I’ve taken a stab at making it easier for folk to make use of this by writing a blog post: https://blog.johnnyreilly.com/2022/04/06/eslint-your-csharp-in-vs-code-with-roslyn-analyzers

If enable code analysis on build is legacy and has no effect, why does it still exist? Is there a blog post explaining not to use this any more?

I guess I wont be using the IDE rules or vsix based analyzers, if I mark something as an error it is because I want it as an error, regardless of whether it’s built through an IDE or command line. I’ll just have to try and get an analyzer from nuget working at compile time, not having any luck yet!

-----Original Message----- From: “Tom Meschter” notifications@github.com Sent: ‎21/‎10/‎2015 17:13 To: “dotnet/roslyn” roslyn@noreply.github.com Cc: “Luke Horsley” luke.horsley@offset1337.co.uk Subject: Re: [roslyn] IDE rules don’t fail builds (#6195)

@Lukazoid This is expected. Those particular rules exist in the IDE, but not in the compiler, so they aren’t run as part of the build. You’ll get the same behavior with any Roslyn-based analyzers installed as a VS extension (VSIX) rather than as NuGet packages or as manually-added analyzer references. A couple of other notes: The Enable Code Analysis on Build check box is a legacy option that has no effect on Roslyn-based diagnostics. Also, the rule set editor shows all the rules that apply to a given project: legacy rules (e.g., Managed Binary Analysis), rules built into the compiler (Microsoft.CodeAnalysis.CSharp), rules built into the IDE (Microsoft.CodeAnalysis.CSharp.Features), and of course rules added by VSIXs, NuGet packages, and manually-added analyzer references. — Reply to this email directly or view it on GitHub.