I want add code analysis (FxCop, not StyleCop) for my dotnet core project, it is targeting netcoreapp1.1 framework. I know that FxCop is built in MSBuild, but when I enabled it, I kept getting error:
1>MSBUILD : error : CA0055 : Could not identify platform for 'C:\Dev\easycube\EasyCube.Authentication\bin\Debug\netcoreapp1.1\EasyCube.Authentication.dll'. 1>MSBUILD : error : CA0052 : No targets were selected.
Then I found that there is Nuget package for dotnet core analyzer Microsoft.NetCore.Analyzers, but I do not know how to use it. Anyone know how to set it up on the project?
Thank you.
A rule set is a grouping of code analysis rules that identify targeted issues and specific conditions for that project. For example, you can apply a rule set that's designed to scan code for publicly available APIs. You can also apply a rule set that includes all the available rules.
Definition(s): A tool that analyzes source code without executing the code. Static code analyzers are designed to review bodies of source code (at the programming language level) or compiled code (at the machine language level) to identify poor coding practices.
ASP.NET Core provides an MVC analyzers package intended for use with web API projects. The analyzers work with controllers annotated with ApiControllerAttribute, while building on web API conventions. The analyzers package notifies you of any controller action that: Returns an undeclared status code.
.Net Core does not support Code Analysis the old way.
You need the Nuget Package Microsoft.CodeAnalysis.FxCopAnalyzers. Add it to your project and you will get the warnings. See here for some more Analyzers.
If you try to run the old code analysis on a solution with .Net Core project you can switch it off for every project (see here) by adding a custom target to the end of the project files:
<Target Name="IgnoreRunCodeAnalysis" Condition=" '$(RunCodeAnalysis)' == 'true' " BeforeTargets="RunCodeAnalysis">
<Message Importance="normal" Text="Set RunCodeAnalysisOnThisProject to false" />
<PropertyGroup>
<RunCodeAnalysisOnThisProject>false</RunCodeAnalysisOnThisProject>
</PropertyGroup>
</Target>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With