1

I installed the ReSharper plugin StyleCop by JetBrains to include StyleCop directly into all of our projects, without the need to have the same settings.stylecop or stylecop.json file in multiple projects (since our guidelines are basically identical for all of our projects).

I ran into an issue regarding StyleCop and after posting an issue on the Github page of the plugin I got told that I should use StyleCop.Analyzers since the plugin has been discontinued.

Now I have the following problem. Do I need to explicitly include a corresponding stylecop.json file within each of our projects to make StyleCop work with the newest features? Or is there another way to tell ReSharper to use a default StyleCop configuration for all of our projects? I know it's not that big of a deal to add a file to a project. But it's a little bit tedious to have the same file within ~50ish projects and then change a single thing. Therefore it would be amazing to configure it in one single location.

Zumpel
  • 82
  • 19
  • Something to bear in mind: you are basically saying that all developers on your project need ReSharper (a paid product) to use your code. Are you sure you want that restriction? Many developers either do not have the funds or otherwise don't use ReSharper (it's an incredible memory/processor hog, and most of the features are available for free built into VS2019). – Neil Mar 16 '21 at 18:06
  • @Neil We are in a closed environment, where everyone has an equally powerful machine. Also ReSharper licensing costs are not a problem since all of the developers are granted Visual Studio Enterprise as well as a ReSharper license. – Zumpel Mar 17 '21 at 10:06
  • It must be nice to work in such an environment. All my previous dev machines ground to a halt as soon as RS was installed, and the teams gradually removed it as it was slowing them down. I've only just upgraded to a laptop that is powerful enough to work with it (12 cores/32 GB/SSD). – Neil Mar 17 '21 at 11:05

1 Answers1

4

The StyleCop.Analyzers NuGet package works with or without ReSharper. It will give you far better control over which projects it should apply to. You can configure it by right clicking the rules under Dependencies->Analysers->StyleCop.Analysers in your solution explorer:

enter image description here

Once you change any configuration it will create a .editorconfig file for you which you could use to copy to all of your other projects if required.

Piers Myers
  • 10,611
  • 6
  • 46
  • 61
  • Thanks for the input. That's exactly the thing I have troubles with. What if we install it on all of our ~50 projects and after a week, we figure out we need to change a rule, for all projects. We have to manually go through all the projects and configure them again. Is there a way to globally set the rules with this approach, so I only need to change them once? – Zumpel Mar 18 '21 at 09:37
  • 1
    The .editorconfig can be placed at the solution level and will apply to all your projects.(https://stackoverflow.com/questions/58626222/how-to-import-an-editorconfig-file-into-visual-studio-for-all-solutions) – Piers Myers Mar 18 '21 at 10:11
  • Sorry, my comment was not clear enough. By projects I meant individual projects, with their own solution and git repository. Each solution contains multiple projects, but this is not an issue, as described in the SO post you linked. Another thing I forgot to mention. Most of those projects are still being worked on, or at least maintained regularly (except ~10-15 projects). – Zumpel Mar 18 '21 at 12:32
  • 1
    Why would your coding standards change so regularly? If you have a build server then you could create a build process that injects the current rules before it builds. When you were using the ReSharper plugin, how were you ensuring that everyone used the same rules and how were changes distributed? – Piers Myers Mar 18 '21 at 14:22
  • We currently have a "base VS configuration". Within the network drive, exported settings files for VS and resharper are stored. If something gets changed, people can easily import those settings. And no, it does not happen regularly. I guess, therefore it makes sense to create a default editorconfig file, which can be inserted in each of the solutions. Anyways, thanks for the discussion. – Zumpel Mar 18 '21 at 15:08
  • >Once you change any configuration it will create a .editorconfig file for you which you could use to copy to all of your other projects if required. How does one generate a .editorconfig? I only ever edit the analyzer config XML directly. – aoetalks Apr 20 '22 at 03:07
  • If this is still an issue for you, Zumpel, you could distribute your .editorconfig via NuGet package as we currently do to ensure consistency across our projects: https://stackoverflow.com/a/67872271/11034016 – Ildrial May 11 '22 at 06:59