Introducing StyleCop on Legacy Projects

A number of people have asked for tips on rolling out StyleCop on a large, pre-existing codebase. This can prove challenging, since the tool will typically generate thousands of violations the first time it is run on existing code. For a large solution, this can make adoption of the tool a bit daunting. On the…

1

StyleCop 4.3 SDK

The SDK documentation for StyleCop 4.3 is now available for download, here: https://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=sourceanalysis&ReleaseId=1425 This documentation explains how to create and install custom StyleCop rules, how to integrate custom settings into the StyleCop settings dialog, and how to create a wrapper for hosting StyleCop in a custom build environment.

4

StyleCop 4.2 MSBuild Integration

This article explains how to integrate the StyleCop tool into an MSBuild based build environment. This type of integration will cause the tool to run automatically whenever the code is built, and StyleCop violations will show up alongside compiler errors in the build output. It is possible to set up the build integration so that StyleCop violations will…

3

StyleCop 4.3 Is Released

The awaited StyleCop 4.3 update is now available. This update includes: Various bugfixes, including fixes for VS integration issues Rules documentation is included and integrated into VS “Show Error Help” New rules (more detail below) Branding change from Source Analysis to StyleCop As promised, we will also be releasing SDK documentation for StyleCop explaining how to author…

34

Clearing up Confusion

There has been some confusion and a few mixed messages coming out of Microsoft since the release of StyleCop, most notably around extensibility support for the tool, and licensing. We’ve gotten a lot of great feedback from the community, and in the last few weeks there have been some good discussions between various teams internally about how…

4

Configuring Hungarian Notation Rules

By default, Microsoft StyleCop does not allow variable or field names to include Hungarian notation. This is enforced by rule SA1305, FieldNamesMustNotUseHungarianNotation. The implementation of this rule is rather straightforward, assuming that any field or variable name which begins with one or two lower-case letters and is followed by an upper-case letter is guilty of…

0

Configuring Results Cache Settings

Each time StyleCop is run, it will cache the results of the analysis onto the disk. The next time StyleCop is run on the same project or file, the tool will determine whether any changes have occured within the file since the last analysis. If not, the previous results are read from the cache. For larger files and projects, this can…

0

Configuring File Header Company and Copyright

It is possible to control the company name and copyright text that is required within the file header at the top of every C# source file. A typical file header looks like the following: //———————————————————————– // <copyright file=”Widget.cs” company=”Sprocket Enterprises”> //     Copyright (c) Sprocket Enterprises. All rights reserved. // </copyright> //———————————————————————–   By default, StyleCop will…

0

A Brief History Of C# Style

A number of astute developers have noted that the C# code style enforced by Microsoft StyleCop differs in some ways from the style typically seen in sample code coming from the Microsoft Developer Division. For example, the very fine book Framework Design Guidelines by Krzysztof Cwalina and Brad Abrams includes many code samples which use a…

34

Sharing StyleCop Settings Across Projects

By default, StyleCop configuration settings are applied on a project by project basis. In a standard installation, each project folder will contain a Settings.SourceAnalysis file, describing the settings for this project. In cases where the default settings are used, there may be no settings file for the project. It is possible, however, to create StyleCop settings files…

0