Preface

When I took interest in StyleCop with Version 4.2 in 2008, the tool was heavily criticized on the Internet. These reactions had their roots in the following points:

  • The tool was not open source
  • The rules implemented were arbitrary rules set by Microsoft and were not to the liking of some people
  • They were not related in any way to how the .Net runtime interpreted our code
  • Some tools previously made by Microsoft were in direct contradiction with the rules laid down for StyleCop

If we look today, all the rules of that time continue to be present and StyleCop has finally been widely accepted. Some of this acceptance is certainly due to the fact Microsoft released the sources of StyleCop to the community with Version 4.3.3, but this is not the only reason.

If we look at how we begin development on medium-sized and large projects, one of the first things we do is establish base principles, and included among them is the definition of coding conventions. These rules, stating how our code must look, are here in order to improve readability and maintainability for all developers of the team. The choices made there are fairly arbitrary and depend on the background and preferences of the person (or the development team) who laid them down.

However, after the project begins, it takes a lot of time and code reviews to follow them.

This is where StyleCop becomes handy. Whether the rules laid down comply with the Microsoft set of rule or the team has to make its own from scratch, the tool, once parameterized, can review the code of the project on command or can even be used in continuous integration to enforce the set of rules previously defined.

What this book covers

Installing StyleCop with Visual Studio (Simple) describes the installation process of StyleCop, and teaches how to configure the rules to be executed on a project and how to launch an analysis from Visual Studio.

Understanding the ReSharper add-in (Simple) describes the StyleCop addin for ReSharper. We will see its real time analysis and how to easily fix most of the StyleCop violations.

Automating StyleCop using MSBuild (Simple) describes how to automate our build process using MSBuild. We will describe which lines need to be added to the MSBuild project in order to enable StyleCop's analysis of it and how to cap the number of violations encountered before the build broke.

Automating StyleCop using command-line batch (Simple) describes how to analyze your projects with StyleCop from the command line. For this, we will use a tool named StyleCopCmd, and prepare it to be able to launch the last version of StyleCop.

Automating StyleCop using NAnt (Intermediate) describes how to use StyleCopCmd to automate our process using NAnt.

Integrating StyleCop analysis results in Jenkins/Hudson (Intermediate) describes how to build a StyleCop analysis job for a project and display its errors.

Customizing file headers (Simple) describes how to customize file headers to avoid StyleCop violations, and how we can use Visual Studio templates and snippets to make our life easier while developing.

Creating custom rules (Intermediate) describes how to create our own custom rule for the StyleCop engine. We will also see how to add parameters to this rule.

Integrating StyleCop in your own tool (Advanced) will show us how to embed StyleCop with your own tools. As an example, we will create a real-time analysis add-in for MonoDevelop/Xamarin Studio.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset