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?
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.
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.
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.
StyleCop is a free source code analysis tool for C# developers that was initially developed by Microsoft.
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:
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:
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.
StyleCop.Analyzers are built upon Rosalyn and make use of the Analyzers feature of Visual Studio 2015. They are available on NuGet:
This would add them into the rules in the relevant *.ruleset
file (same place as CodeAnalysis rules, accessible from the project page:)
giving:
and you can run them via
Which has the same effect as right click, Run StyleCop, used on previous versions and with Visual StyleCop.
Giving:
The source code is available on GitHub, so adding custom rules should be possible.
Install:
Which gives this in 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With