Skip to content

Writing Custom Rules for StyleCop

Christophe HEISER edited this page Aug 16, 2015 · 2 revisions

StyleCop provides an extensible framework for plugging in custom rules. A custom rules analyzer checks the contents of a source code file for adherence to one or more rules which are not already covered by the default set of rules shipping with the tool. Custom StyleCop rules will typically cover style and consistency guidelines, similar to the default rules.

  1. The first step in creating a custom StyleCop rules analyzer is to create a new class library containing the code which executes the rules. To learn how to create a new StyleCop rules analyzer class, see the Authoring a Custom StyleCop Rule topic.

    The project containing your custom rules analyzer must also contain an Xml file which describes the rules exposed by your analyzer. See the Authoring Rules Metadata topic for help creating a metadata file for your analyzer.

    If your custom rules should expose settings that can be configured by the user, it may be desirable to define properties which will be displayed on the standard StyleCop settings dialog. To learn how to author and display custom StyleCop rules properties, see the Adding Custom Rule Settings topic.

    The final step in creating a custom StyleCop rules analyzer is building and installing the assembly containing the code and metadata. The Installing a Custom Rule topic describes how to install a custom rules analyzer.

Clone this wiki locally