Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
434 views
in Technique[技术] by (71.8m points)

c# - Question on Microsoft.CodeAnalysis.NetAnalyzers and FxCop analyzers

in my .net project(Target Framework 4.7), in code analysis tab, I see Run on build was checked. so am able to see some FxCop warnings. but when I checked nuGet packages, I see that Microsoft.CodeAnalysis.FxCopAnalyzers is not installed. so my first question is when FxCopAnalyzers nuget package is not installed, how are the warnings showing up?

Moving now, when I upgraded to VS2019, I get below error

Warning CA0507 Post-build Code Analysis (FxCopCmd.exe) has been deprecated in favor of FxCop analyzers

so I googled and found that FxCopAnalyzers are no longer supported and are replaced with Microsoft.CodeAnalysis.NetAnalyzers.

I did the steps mentioned here https://github.com/dotnet/roslyn-analyzers

  1. installed the package

  2. did this to the project file by editing it in notepad.

    enter image description here

the Warning CA050 is gone now, but I don't get any warnings that was coming before. I was expecting Microsoft.CodeAnalysis.NetAnalyzers to generate the same set of warning that was coming before(even thouugh i dont know how it was coming). What am I missing? am not sure if Microsoft.CodeAnalysis.NetAnalyzers is even doing its job.

Thanks in Advance.

question from:https://stackoverflow.com/questions/65894661/question-on-microsoft-codeanalysis-netanalyzers-and-fxcop-analyzers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have too little reputation to comment. I recommend reading this: https://docs.microsoft.com/en-us/visualstudio/code-quality/net-analyzers-faq?view=vs-2019

TLDR: FxCop when used as a Roslyn analyzer is not the same analyzer as FxCop in Visual Studio (legacy FxCop). Some rules from legacy FxCop are not present in newer FxCop.

For a list of rules that have not been ported, see below:

https://docs.microsoft.com/en-us/visualstudio/code-quality/fxcop-unported-rules-may-get-ported?view=vs-2019

https://docs.microsoft.com/en-us/visualstudio/code-quality/fxcop-unported-deprecated-rules?view=vs-2019


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...