Microsoft.CodeAnalysis.NetAnalyzers not doing anything at all

Endasil 26 Reputation points
2021-02-03T21:07:29.353+00:00

So I switched from using the fxcop nuget to the new Microsoft.CodeAnalysis.NetAnalyzers NuGet and it does nothing at all. I added the following to my csproj file expecting it to apply all rules but nothing happens when i build. I uploaded an example project https://easyupload.io/iktg0k

I added the following to my csproj file
<PropertyGroup>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisLevel>latest</AnalysisLevel>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
</PropertyGroup>

my application looks like this and should generate https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1819

namespace ConsoleApp1  
{  
    public class Book  
    {  
        private string[] _Pages;  
  
        public Book(string[] pages)  
        {  
            _Pages = pages;  
        }  
  
        public string[] Pages  
        {  
            get { return _Pages; }  
        }  
    }  
  
    class Program  
    {  
        static void Main(string[] args)  
        {  
        }  
    }  
}  
Developer technologies C#
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Timon Yang-MSFT 9,606 Reputation points
    2021-02-04T06:33:10.377+00:00

    Although the documentation says that the analyzers work for projects that target net5.0 as well as earlier .NET versions, such as netcoreapp3.1 and net472.

    But when I tested it, it took effect immediately after using it in the .Net Core3.1 project and adding the configuration information you provided.
    63836-1.png
    But for .Net Framework 4.7.2, it is always useless. I'm not sure if this is a design flaw of the package or different configuration information is required in the .Net framework.

    I suggest you ask for confirmation in its GitHub repository.


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    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.