How to use stylecop rules with resharper

Hi, I'm currently evaluating R# with the 30-day trial version. I have a project that already uses StyleCop (version 4.7.45) with customized settings. Now, I'd like to have R# automatically format my code on "Code cleanup" such that the StyleCop warnings are resolved.

How do I achieve that?

I understand that this must somehow be done by using the StyleCop plugin. However, in Visual Studio under  "Resharper->Options->Tools" there's no entry for StyleCop ...

What must I do to enable StyleCop in R#? Or should this be done differently?


Comment actions Permalink
Official comment

It might be that ReSharper's global or solution settings are overriding the StyleCop defaults. When the plugin is installed, it updates ReSharper's default settings for formatting and Code Style to match the StyleCop rules. However, it only alters the defaults - if you've changed any settings in global or solution settings, these can still override the defaults.

Please go to ReSharper → Options → StyleCop and click the "Reset StyleCop options" button. If it's greyed out, it means everything's already set correctly. If not, then some of the defaults are being overridden. Once clicked, please try to run Code Cleanup again. Hopefully, this should fix the issue you're seeing - if not, please let us know, and we can investigate further.

Comment actions Permalink

Hello Bernhard,

When you launch StyleCop installer, there should be a dialog about what will be installed and you need to be sure "Will be installed on local hard drive" is chosen for "R# Integration". Then StyleCop will be installed as ReSharper plugin.

Atfer that you may find StyleCop settings here:
1) ReSharper | Options | Code Editing | Code Cleanup | Create custom profile | StyleCop.
2) ReSharper | Options | Tools | StyleCop

Hope it helps.

Comment actions Permalink

Ah, I understand: The cause for my problem was that I installed R# after StyleCop. The StyleCop installer does not let you choose R# integration if R# is not installed on your machine. Thus, I couldn't install R# integration when I installed StyleCop and consequently, R# did not find StyleCop.

Fortunately, the StyleCop installer is smart enough to let you just update your StyleCop installation with R# integration. I've re-run it, and now R# sees StyleCop.

I've not yet attempted code cleanup, though.

Thanks for your help, Alexander!

Comment actions Permalink

I effectively have the same issue using

  • VS 2015
  • StyleCop 5.0.6419.0
  • StyleCop by JetBrains 2017.2.0
  • ReSharper 2017.2.2

When I run code clean up the rule for having using statements within a namespace is not fixed but in the file it shows a warning.  So it seems the StyleCop violation is detected but it's not taken into consideration in code clean up.  Any help is appreciated.  Thanks.

Comment actions Permalink

@Matt Ellis It looks like that fixed it.  Thanks a ton!


Please sign in to leave a comment.