14

Someone on our team installed StyleCop and since then all of the projects he loaded up and committed to source control refuse to load unless stylecop is installed.

I know I can manually edit the .csproj files to get rid of it, but is there an easy way to automatically remove these stylecop parts from the project files so they can be loaded and built on a non-stylecop-infected Visual Studio machine?

Mikael Engver
  • 4,634
  • 4
  • 46
  • 53
gbjbaanb
  • 51,617
  • 12
  • 104
  • 148
  • Have you removed all references to the StyleCop assemblies in your projects? You can remove these references through Visual Studio. – Bernard Dec 09 '10 at 14:08
  • I recommend that you still make use of StyleCop, it does add value, but perhaps you should use it externally so that you need not make any changes to your existing projects. – Bernard Dec 09 '10 at 14:10
  • 1
    I thought StyleCop was a tool for Visual Studio that allowed you to highlight rules that have been broken in your source code via the IDE, why would you need to add a reference to it from your project? I've been using StyleCop for a while now and not seen it add anything to my project or source files. – Piers Myers Jan 28 '11 at 21:11
  • @Piers: The rules are not necessarily highlighted in the IDE. If you insert two lines in each .csproj file and put the StyleCop dlls in your project folder, violated rules cause errors when you compile...no matter if you compile in Visual Studio or with MSBuild, and no need to install it on every developer machine. – Christian Specht Feb 04 '11 at 00:56
  • Piers, I just posted an answer with a link. You can check out the link if you are interested in how this works. – Christian Specht Feb 04 '11 at 01:18
  • @haarrrgh - thanks for clearing that up for me. I have to admit that I have only used StyleCop on a solo project and not done the integrated MSBuild. – Piers Myers Feb 04 '11 at 14:38
  • 2
    I came to this question because when I removed StyleCop and whenever I loaded VS or projects it gave me a warning that the package didn't load correctly. I couldn't find an answer anywhere but I solved it using `devenv /Setup` & `devenv /ResetSettings`. Hope it helps someone. – MasterMastic Jan 30 '13 at 15:43

4 Answers4

22

Why remove it?
In my opinion using StyleCop is a good thing.
Your only problem seems to be that your team member didn't set up StyleCop properly.

From your description, I guess that he wanted to set up StyleCop with MSBuild integration: http://blogs.msdn.com/b/sourceanalysis/archive/2008/05/24/source-analysis-msbuild-integration.aspx

He apparently just left out the last paragraph "Team Development": copy the StyleCop files into your project and check them into source control, so you don't need to install StyleCop on every single developer machine. (see my link for a more detailed description)

If you do this, StyleCop should work on every machine, no matter if it's installed or not.

We are using StyleCop in this way as well, and I think it's the easiest way to use it.
I just had to insert two lines into each .csproj file and check a few files into source control once...and StyleCop just works, on every compile, on every machine (no matter if it's on a developer machine or the build server).

Christian Specht
  • 35,843
  • 15
  • 128
  • 182
  • 17
    Stylecop is not a good thing. We don;t always have control over the code we work with - in particular the 'core' code we have is written by a different team in another country and .. lets say the default stylecop options create only a few thousand violations. and they don't have a consistent system, so we either live with those warnings or get rid of it in our code and just go back to the old fashioned way of making our code look nice without any 'help'. – gbjbaanb Feb 04 '11 at 09:50
  • which leave me with the problem of getting rid of thsoe 2 csproj lines - as once in, they error if you don't have stylecop installed. (or an older version of stylecop - so if the build server has v1 and someone upgrades their local copy, the build server starts to error. PiTA) – gbjbaanb Feb 04 '11 at 09:52
  • 11
    You can disable certain rules in StyleCop. And you can enable StyleCop only for certain projects. So if the code from the other team violates too many rules, you can just disable Stylecop for their code and keep it enabled for yours. – Christian Specht Feb 04 '11 at 11:59
  • 3
    Concerning "they error if you don't have stylecop installed": They don't if you put the StyleCop files in your project and check them into source control. Take a look at the link in my answer, it has a detailed description of that (in the last paragraph "Team Development"). – Christian Specht Feb 04 '11 at 12:03
  • check the stylecop binaries into SCM and (I assume) get them out everytime you build?! You might as well install it everywhere rather than manage the dependancy. That link doesn't really provide a good answer. I'd still ratehr get rid of it - we are an agile shop so I'd prefer communication to solve this kind of problem rather than impose a rigid tool that breaks the build. – gbjbaanb Feb 09 '11 at 16:00
  • 10
    StyleCop encourages people to document things which dont' need documenting (eg properties with obvious names like "Surname") and doesn't do anything to document complex code. As such it causes developers to neglect important documention while impeding their workflow writing very basic code. The code also becomes bloated with unnecessary formatting which impares readability. – NickG May 30 '13 at 16:15
  • I installed a StyleCop NuGet package thinking it was something that only applied to one project that I could just uninstall later. Unfortunately StyleCop analyzers showed up universally in every solution even though most projects already have their own analyzers, and uninstalling the package did nothing to help. StyleCop also wasn't found under "remove programs." – Kyle Delaney Mar 13 '20 at 21:34
20

Stylecop hides real warnings. Its a vanity exercise and its evil.

Do not use it.

I find that stylecop generates many many trivial warnings that drown out the real warnings. By all means use these tools but don't force them to be on. Having no stylecop warnings is a meaningless metric.

Stephen
  • 819
  • 8
  • 8
  • 4
    How does it hide real warnings? – MasterMastic Jan 30 '13 at 15:13
  • 7
    It hides real warnings because some developers look and say 'look no style cop issues!' despite writing terrible, unmaintainable spaghetti code. – Po-ta-toe Feb 21 '13 at 14:49
  • 23
    Every tool has to be used with according to its purpose. Stylecop does not say your code is OK, it says, that its formatting is consistent with the set of rules. Same as automatic merge in any VCS (svn/git) never says you have your code sonsistent after the merge: it just says, that all the changes have been merged together according to the merge rules. However it is you responsibility to ensure the code is consistent (e.g. everyting compiles and unit tests pass). – Isantipov Mar 15 '13 at 15:12
  • I find that stylecop generates many many trivial warnings that drown out the real warnings. By all means use these tools but don't force them to be on. Having no stylecop warnings is a meaningless metric. – Stephen Mar 13 '14 at 22:20
  • 5
    StyleCop is a fantastic tool. Disable the warnings that you don't agree with. – GaTechThomas Mar 25 '15 at 16:44
15

I disabled StyleCop by adding the following GlobalSettings configuration to the file settings.stylecop in the solution root.

<StyleCopSettings Version="4.3">
  <GlobalSettings>
    <BooleanProperty Name="RulesEnabledByDefault">False</BooleanProperty>
  </GlobalSettings>
  ...
</StyleCopSettings>
Mikael Engver
  • 4,634
  • 4
  • 46
  • 53
14

TEST DRIVEN DEVELOPMENT

Red -> Green -> Refactor

TEST DRIVEN DEVELOPMENT (WITH STYLECOP)

Red -> Red -> WTF? -> Red -> Red -> ...

Also, from here:

Bob: Using pattern matching, the software identifies ugly code
Charlie: —and fixes it!
Bob: No. It prints a message about each transgression.
Charlie: And then the user right-clicks to fix them all?
Bob: No. The message scolds them 'invalid spacing around the comma'.
Charlie: And then explains how the user can fix it?
Bob: No, that information is in a separate document.
Charlie: On Google?
Bob: No.


This is why don't use Stylecop.

Community
  • 1
  • 1
tom redfern
  • 30,562
  • 14
  • 91
  • 126