Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code analysis for dotnet core project in VS2017

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.

like image 445
anggiputper Avatar asked May 25 '17 12:05

anggiputper


People also ask

What is a rule set in coding?

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.

What is a code analyzer?

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.

What is Analyzer in ASP.NET Core?

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.


1 Answers

.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>
like image 192
habakuk Avatar answered Oct 17 '22 04:10

habakuk