Enabling FxCop Code Analysis on .NET Core


Enabling FxCop Code Analysis on .NET Core.


Description :- Code Analysis is important Because it is helpful from many aspects like Code Quality, Code Correctness, Code maintainability will remain great code for long time.


Step 1. 

Install Nuget Package : Microsoft.CodeAnalysis.FxCopAnalyzers  Click Here to install Nuget.

Refer Below screen shot additional packages will be installed after installing.


Step 2.

File with name FxCop.ruleset will be created in solution when you try to change action by right clicking on rule in visual studio as shown below. where you can find list of rule to be configured.






If you have multi layer Architecture and you want to use similar ruleset for all layers then move ruleset file at parent level of project and add reference of that ruleset file to each project were we need to add FxCop rules.

Ruleset path can be set at csproj level as below. I have added CodeAnalysisRuleSet within PropertyGroup with relevant path of code analysis ruleset file.


 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
   <CodeAnalysisRuleSet>../CustomFxCop.ruleset</CodeAnalysisRuleSet>
 </PropertyGroup>

Above code will be use for Debug mode.



Above screen Shot shows list of rules, you can modify rule by opening it in notepad++ or you can do it in visual studio too. You can change Action as per your project requirement like Error, Warning , Info etc...


Here i have Configured rule CA1052 as warning. when this rule will be violated then it will show warning to end developers as below screen shot.



Here your Fxcop setup is ready for use. Add Comment for any query of confusion.

No comments

Powered by Blogger.