How to fire .net analyzers also running project

Fabrizio Mancin 0 Reputation points
2024-04-12T08:20:03.8366667+00:00

Hi guys,

I'm in trouble with .net analyzers; they works fine building the project but they aren't fired running the project.

I don't found any solution either on StackOverflow

https://stackoverflow.com/questions/78305147/how-i-can-run-code-analysis-in-net-6-8-application-on-debug-start

Step to reproduce

  • Visual Studio 2022 v. 17.9.6
  • New Project Console application .NET 8
  • Install nuget package StyleCop.Analyzers 1.2.0-beta.556
  • new local file .editorconfig with the following configuration
    root = true

[*.{cs}]

dotnet_diagnostic.SA1507.severity = error # Code should not contain multiple blank lines in a row

  • in program.cs add two lines above Console.WriteLine("Hello, World!");

Any ideas??

Thank you!

Developer technologies .NET Other
Developer technologies Visual Studio Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. S.Sengupta 24,476 Reputation points MVP
    2024-05-04T00:52:39.7433333+00:00

    .NET analyzers typically run during the build process, not when you directly run the application.

    If you're using Visual Studio 2022 version 17.4 or later, you can enable Roslyn Analyzers to run during debugging. Here's how:

    • Go to Tools > Options > Text Editor > Code Analysis.
    • Check the box for "Enable Roslyn analyzers during debugging." ========== Ensure you have the latest version of the .NET SDK installed.
    • Some analyzers might require specific configuration to enable code lens features. Refer to the analyzer's documentation for details.
    0 comments No comments

  2. Fabrizio Mancin 0 Reputation points
    2024-05-07T07:47:56.8366667+00:00

    I found the solution by myself unchecking the box below

    User's image

    VS 17.9.6

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.