Skip to content
March 6, 2019 / inventcrm

Stylecop for Dynamics CRM

StyleCop is a static code analysis tool from Microsoft that checks C# code for conformance to StyleCop’s recommended coding styles and Microsoft’s .NET Framework Design Guidelines. StyleCop analyzes the source code, allowing it to enforce a different set of rules from FxCop. The following features are required for

• Documentation
• Layout
• Maintainability
• Naming
• Ordering
• Readability
• Spacing

StyleCop includes both GUI and command line versions of the tool. It is possible to create new rules to be used

Download from following link:

https://marketplace.visualstudio.com/items?itemName=ChrisDahlberg.StyleCop#overview

Installation

The StyleCop can be installed as a NuGet Package or a Visual Studio Extension Installer (VSIX).

2.2.1 NuGet Installation

  1. Open Visual Studio
  2. Choose Tools – > NuGet Package Manager -> Manage NuGet Packages for Solution
  3. Search for Style Cop and Install The NuGet Package.
  4. Once Installed, Restart Visual Studio to experience changes.

2.2.2 VSIX Installation

  1. Open Visual Studio
  2. Choose Tools – > Extensions and Updates
  3. Search for Style Cop and Install The NuGet Package.
  4. Once Installed, Restart Visual Studio to experience changes.

Procedure

The following procedure provides the analysis of the C# code.

  1. Select the file (Example.cs) from the Solution Explorer
  2. Right Click on The file to view the context menu.
  3. Click “Run StyleCop” to view analysis.
  4. The Warnings and Error List is shown in the error log.

Stylecop also provides Statistical Analysis of the C# code in the output window on every build of the Solution or Project

Note: Any File or Folder can be excluded from StyleCop Build by Choosing the Exclude from StyleCop Option in The Context Menu of any file from solution Explorer or Document Window.

Common Warnings & Errors

Some of the common Errors and warnings encountered from our developments are:

  • All using Directives must be placed inside of the namespace
  • An open curly bracket must not be followed by a blank line
  • The Code must not contain multiple blank lines in a row
  • Adjacent Blank Lines must by a blank line
  • The method must have a documentation header

Hope this blog post helps you.

Leave a comment