Introducing Stylecop With Code Analyzer in Visual Studio 2015

As per the styplecop project the support for Visual Studio 2015 is not yet ready. Not sure if there will be any support available in the future because Visual Studio 2015 now has it's built-in code analyzer that can adapt to any provided code analyzer and run the ruleset accordingly against the project code files.

Getting the style cop running with Visual Studio 2015

Installing StyleCop.Analyzers (currently in pre-release version) Nuget package in Visual Studio 2015 project. Be sure to select “include prerelease” checkbox before searching.



I like the new Nuget package manager, Professional.

After the installation of Stylecop.Analyzers Nuget package, expand the Reference tree and look for the Analyzers.



Now right-click on it and select “Open Active Ruleset”. This will open the list of Analyzers and their rule sets.



Now you can select and customize the Ruleset to run for your code. Now when you press save, this will add a new file “<your projectname>.ruleset” within the project. This customized Ruleset file can be used across the projects.

Managing the Rulesets across Projects

To manage the Rulesets across the projects you can configure the mapping of the Ruleset. Here is the procedure:

  • Click on Analyze from Menu and select Configure Code Analysis for solution


This will open a window and provide the option to choose which ruleset to run against each project. You can choose the same file that you created for all projects or you can use separate ruleset files for individual projects.



Now that you have created a custom rule set file and setup the Ruleset for projects in a solution, you can launch the code analysis on the Solution level.

Launching the Code analysis

Analyze: Run Code Analysis for Solution (Allt + F11)

This should gives results in the Error window.



Now you have the code analysis result from your old friend styleCop. I hope this would help you untill we hear from other sources.

Thanks to John Koerner's article for guiding towards the stylecop.Analyzers Nuget package thing.

Up Next
    Ebook Download
    View all
    Learn
    View all