60

Is there a lint-like tool for C#? I've got the compiler to flag warnings-as-errors, and I've got Stylecop, but these only catch the most egregious errors. Are there any other must-have tools that point out probably-dumb things I'm doing?

double-beep
  • 5,031
  • 17
  • 33
  • 41
Ken
  • 2,651
  • 3
  • 19
  • 17

6 Answers6

47

Tried FxCop? It's integrated into VS as "Code Analysis"

In the newer versions of Visual Studio, it is called "Microsoft Code Analysis" and can be downloaded from the Visual Studio Marketplace: https://marketplace.visualstudio.com/items?itemName=VisualStudioPlatformTeam.MicrosoftCodeAnalysis2017

Mehrdad Afshari
  • 414,610
  • 91
  • 852
  • 789
  • 1
    I don't use VS but since you got 4 upvotes in 17 minutes it probably deserves a try. Installing it now, thanks! – Ken Apr 14 '09 at 18:04
  • 5
    It works without VS too. But VS is a great tool for .NET development. – Mehrdad Afshari Apr 14 '09 at 18:08
  • 2
    I think it would be pretty hard to convince me that VS (which I have tried, and disliked) is better than Emacs + 15 years of customizations. It would probably be easier to get me to change keyboard layouts! – Ken Apr 14 '09 at 20:32
  • 17
    BTW, while you might be comfortable with writing code in Emacs, .NET development is much more than just coding. You can always have VS at hand for visual debugging and other stuff. It doesn't hurt. – Mehrdad Afshari Apr 14 '09 at 20:42
  • 2
    Link for FxCop 10.0 (for .NET 4.0, it's in the 7.1 SDK): http://blogs.msdn.com/b/codeanalysis/archive/2010/07/26/fxcop-10-0-is-available.aspx – JohnB Aug 25 '10 at 16:58
20

SonarLint (free, open source) is pretty sweet!

SonarLint for Visual Studio is based on and benefits from the .NET Compiler Platform ("Roslyn") and its code analysis API to provide a fully-integrated user experience in Visual Studio 2015. SonarLint is free, open source, and available in the Visual Studio Gallery.

Mrchief
  • 75,126
  • 20
  • 142
  • 189
20

Resharper performs a fair bit of static analysis as well as doing a ton of other useful things. Since version 8.0 analysis can run in command line mode. Currently I wouldn't code in C# without it.

As well as FxCop, Gendarme is another tool to look at (it is Mono's version of FxCop but they are different in approach and the errors that they actually find).

Community
  • 1
  • 1
Kris Erickson
  • 33,454
  • 26
  • 120
  • 175
5

Gendarme for Mono is similar to FxCop

Johan Bezem
  • 2,582
  • 1
  • 20
  • 47
Nathan Koop
  • 24,803
  • 25
  • 90
  • 125
0

You can try .Net Reflector by Red-Gate, you can get it from here. Many useful plugins for .Net Reflector are available on CodePlex which you can get it from here.

this. __curious_geek
  • 42,787
  • 22
  • 113
  • 137
  • 1
    I use Reflector all the time, but AFAICT it's just for inspecting compiled code. Is there some "show me my stupid mistakes" module I'm missing? – Ken Apr 14 '09 at 17:59
  • Good lord yes. I don't know what you need to do to turn it on (more like, what you've done to turn it off), but dig for it, it's terrific. – Robert Rossney Apr 14 '09 at 18:08
  • now that Reflector is a commercial product, ILSpy is a good open source alternative ... at least for inspection and disassembly, I've no idea if it has the same sorts of analysis tools – yoyo Jan 04 '13 at 19:01
-1

This question already has an answer, but for reference...

You can try PVS-Studio. That's not free, but, IMHO, must have one. Quote from their site:

PVS-Studio is a tool used to detect bugs in the source code of programs written in C, C++ and C#.

PVS-Studio performs static code analysis and generates a report that helps a programmer find and fix bugs. PVS-Studio does a wide range of code checks; but it is especially useful to search for misprints and Copy-Paste errors.

The analyzer is designed for developers who use Visual Studio.

Community
  • 1
  • 1
dimhotepus
  • 64
  • 8