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
- Open Visual Studio
- Choose Tools – > NuGet Package Manager -> Manage NuGet Packages for Solution
- Search for Style Cop and Install The NuGet Package.
- Once Installed, Restart Visual Studio to experience changes.
2.2.2 VSIX Installation
- Open Visual Studio
- Choose Tools – > Extensions and Updates
- Search for Style Cop and Install The NuGet Package.
- Once Installed, Restart Visual Studio to experience changes.
Procedure
The following procedure provides the analysis of the C# code.
- Select the file (Example.cs) from the Solution Explorer
- Right Click on The file to view the context menu.
- Click “Run StyleCop” to view analysis.
- 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