C # code specification and Quality Check Tool StyleCop. Analyzers,
Introduction
I used ReSharper for code quality check all the time, but it is charged after all. So I want to find a free one that can be promoted to my colleagues in the company. After searching, I found StyleCop, But I installed StyleCop in VS 2015 or installed StyleCop through the Nuget package. MSBuild: although the system can display the warning in the Error List after compilation, you cannot use the project --- Right-click the rule to configure StyleCop, and finally find a new version of StyleCopAnalyzers.
Visual Studio 2015's Roslyn analysis tool is mainly used, which brings the following benefits:
- Supports C #6
- Using the Roslyn parser reduces the performance consumption of the custom parser
- The parser runs when you write code, and runs when you compile the Code. (You do not need to set the msbuild task or install any vs plug-in)
Install
It's easy to install. Manage the NuGet package in the project, input StyleCop. Analyzers, and then install it.
After the installation is complete, you can see the effect. StyleCop. Analyzers will prompt errors when you write code like ReSharper, instead of discovering errors after compilation.
However, after compilation, all the error prompts will be displayed.
Configure custom rules
In the above picture, we can see that my project has a total of 32 StyleCop warnings. Below we will remove the SA1652 warning.
Find the reference Analyzer and right-click Open Active Rule Set to Open the Rule table.
Find the rule SA1652 of StyleCop. Analyzers, deselect the check box, and then save it.
A file with the. ruleset suffix will be generated in the project, which is our custom rule.
After compilation, check the effect and you will find that the SA1652 warning is no longer displayed.