Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is StyleCop 4.7 compatible with C# 6.0 code

I installed StyleCop 4.7 for developing customized rules, to analyze our C# code.

We write the code in Visual Studio 2015. I can analyze my C# 5.0 (Visual Studio 2013) code, and I get correct response, but when I analyze my C# 6.0 (Visual Studio 2015) code, StyleCop raises an exception for my rules.

Now my question is:

Is StyleCop 4.7 compatible with C# 6.0 code? If not, do we have any solution?

like image 705
user2352554 Avatar asked Jan 31 '16 11:01

user2352554


People also ask

Is StyleCop still used?

StyleCop used to be a Visual Studio plugin and a NuGet package. You can still use this in Visual Studio 2019, but the current recommended way to use StyleCop is to use the Roslyn-based analyzers.

How StyleCop works?

StyleCop analyzes C# code with a set of rules to check whether the code follows the rules. You can download StyleCop from this link. If you click on the downloads section, you will see three setups, one is the StyleCop setup which actually installs the software and the other two are CHM help files.

What is StyleCop analyzers?

StyleCop is an open-source static code analysis tool from Microsoft that checks C# code for conformance to StyleCop's recommended coding styles and a subset of Microsoft's . NET Framework Design Guidelines.

Is StyleCop free?

StyleCop is a free source code analysis tool for C# developers that was initially developed by Microsoft.


1 Answers

TL;DR - Yes. StyleCop 4.7 was updated to be compatible with C# 6 starting with 4.7.51 (Beta) released on 13th March 2016.
There was a handover to new custodians back in January 2016, and a new version 4.7.50 alpha has been released 3rd Feb 2016, but as yet does not include C# 6 support.
4.7.51 (Beta) was released on 13th March 2016 and the latest stable is 4.7.54 released May 13th.


Here are three other options that work with Visual Studio 2015:

1. Visual StyleCop

Visual StyleCop, is an extension to Visual Studio. This gives you the right click functionality into Visual Studio 2015 that installing StyleCop gave you for 2013 and below.

This is available by adding an extension into Visual Studio:

Visual StyleCop

It is an active project and will give you StyleCop on C# 6 features. There is a package - Visual-StyleCop.MSBuild, that will give you MSBuild integration.

It is possible to write custom rules with Visual StyleCop.

2. StyleCop Analyzers

StyleCop.Analyzers are built upon Rosalyn and make use of the Analyzers feature of Visual Studio 2015. They are available on NuGet:

StyleCop.Analyzers NuGet Package

This would add them into the rules in the relevant *.ruleset file (same place as CodeAnalysis rules, accessible from the project page:)

Project Page

giving:

RuleSet Example

and you can run them via

Run Analyzerss Example

Which has the same effect as right click, Run StyleCop, used on previous versions and with Visual StyleCop.

Giving:

Example Errors

The source code is available on GitHub, so adding custom rules should be possible.

3. Resharper, with StyleCop by Jetbrains

Install:

  • Resharper 10.0.1
  • StyleCop by JetBrains 4.8

R# StyleCop Plugin

Which gives this in R# options: R# Options

This gives you syntax highlighting, but no right click run, and no build integration. Additionally, R# is not a free product.

You can extend it using plugins, but it doesn't feel as customizable as the other two options presented.

like image 151
NikolaiDante Avatar answered Sep 23 '22 03:09

NikolaiDante