Tools

Namespaces

Variants

Views

Actions

Search

Contents

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Contents

Introduction

It's always a good practice to keep a check on the coding standards used in the project irrespective of the number of developers involved in it. It not only helps in readability and understanding but saves lots of time and resources in the maintenance phase as well. StyleCop is such a FREE .NET tool which enforces a consistent style to be used in the project.

Note: As mentioned here, StyleCop tool can be used to check C# development guidelines only. It can't be used to check XAML guidelines.

If we try to build/run this sample piece of code then it will compile/run successfully.

Running StyleCop

We will now run StyleCop to check if there are any C# development constraints we haven't met and if yes, then how many? To run StyleCop, simply right click on any page inside the application and choose Run StyleCop option or go through Tools>>Run StyleCop.

The results of the StyleCop tool can be viewed in the form of Warnings in the Error List window as shown below.

You can see, we have 19 StyleCop warnings in our project consisting of just one file and one very simple function. All these warnings are showing that we've not met the guidelines of C# development. Now you can imagine how many warnings would be there in our regular average projects and how much uneasy it would be for any other developer who used to follow C# guidelines immensely.
The situation even gets worse when we(the developers), at times, need to deposit our source code to our clients as it puts a negative impression on them.

Removing StyleCop Warnings

The StyleCop warnings can be removed easily when read. So, after removing most of the StyleCop warnings our code looks like shown below.

StyleCop Settings

We have an option to remove some or all of the predefined settings set by StyleCop. These settings can be accessed by selecting the project in the Solution Explorer window, right clicking and choosing StyleCop Settings. By default all the settings are applied but we can modify them as per our project's/time's requirement.

Default view of StyleCop Settings

Assuming we don't want to handle below mentioned kind of warnings.

Remaining StyleCop warnings

For this, we can deselect the relevant check box(s) from the StyleCopSettings as shown below.

Modifying StyleCop Settings

After applying above settings, if we again try to re run StyleCop, we will see all the warnings have been removed.

No warnings

Summary

This way we can keep a check that all of us (developers) met with the C# development guidelines using StyleCop tool while making Windows Phone apps.