C # code specification and Quality Check Tool StyleCop. Analyzers,

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.