Home > front end >  Code Analysis CA1307 & CA1310 not working in new .NET 6 projects
Code Analysis CA1307 & CA1310 not working in new .NET 6 projects

Time:01-26

I'm using Visual Studio 2022 (17.4.4), and when I create a new empty .NET 6 project, Code Analysis doesn't work.

According to MSDN, Roslyn Code Analyzers are automatically enabled for every new .NET 6 project:

Starting in Visual Studio 2019 16.8 and .NET 5.0, these analyzers are included with the .NET SDK. Analysis is enabled, by default, for projects that target .NET 5.0 or later.

Here's the steps I followed:

  1. Start Visual Studio
  2. Create a new .NET 6 Console Project
  3. Paste the code below
  4. Click Analyze -> Run Code Analysis. I would expect to get CA1307 or CA1310 - however, I get neither.

How can I get Code Analysis to work here?

Console.WriteLine("asdf".IndexOf("/")); // expecting CA1307 or CA1310 here
Console.WriteLine("Hello, World!");

CodePudding user response:

Since 5.0 CA1307 is Disabled and CA13010 is Hidden you can have a complete view of Roslyn rules here

  • Related