2015-10-09

Installing StyleCop in Visual Studio

StyleCop is a tool that reports problems with the source code in C#. Up through Visual Studio 2013, it is provided as an extension to Visual Studio. For Visual Studio 2013 and earlier, StyleCop could be downloaded and installed from http://stylecop.codeplex.com/. The source code is available there as well.

For Visual Studio 2015, the way that extensions are installed changed. Because extensions from 2013 don't work the same way as 2015, the 2013 version of StyleCop won't work in Visual Studio 2015. A person branched the StyleCop 2013 sources and produced a 2015 version. The sources are available at https://github.com/Visual-Stylecop/Visual-StyleCop, however the package for it can be downloaded from the Visual Studio 2015 Extensions and Updates menu item. Search for "Visual StyleCop" in the online extensions and install the version there. This will work essentially the same as Visual Studio 2013 using the same parser for C# and interface into Visual Studio. Currently there are some issues with parsing the new syntax available with C# version 6, but they are getting resolved.

However Visual Studio 2015 has added a new feature: Custom Analyzers. These use the features of the Roslyn compiler to parse the source code. They also integrate into Visual Studio to provide an interface for fixing the reported problems. They can report problems at the time the code is written, not just after a compile. Custom Analyzers are clearly the way forward for tools like StyleCop.

A group of people have re-implemented StyleCop as a Visual Studio 2015 Analyzer. The source code is available at https://github.com/DotNetAnalyzers/StyleCopAnalyzers. The package can be installed from NuGet console by typing "install-package stylecop.analyzers -pre". Because, unlike previous versions of StyleCop, these analyzers don't have a configuration dialog, they must be configured in JSON code. Read the document at https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/Configuration.md on how to configure the settings.

No comments :

Post a Comment

Note: Only a member of this blog may post a comment.