Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code analysis/FxCop in VS2008

FxCops is something new to me, but as always I would like to get to know the new things.. From what I've read, FxCops is already included in VS2008. I guess it's the "Code Analysis" function. Whenever I try to run it though, it seems to start a rebuild and end in the "Finished Rebuilding" state.
I checked the output window and there are a bunch of warnings there. But if I'm not mistaking, there should be more of a GUI for this then the wall of text in my output window, right?
Am I missing a window that should have popped up? Can I open it somewhere? Or is there anything else I'm missing?

like image 836
Boris Callens Avatar asked Dec 18 '08 08:12

Boris Callens


4 Answers

Yes, Code Analysis is the nice friendly name for FxCop. However, I'm not aware of a friendly window beyond the errors / warning list where they should appear, prefixed CA.

On the project properties screen there is a Code analysis tab where you can treat warnings as errors to enforce the rules you care about.

like image 84
NikolaiDante Avatar answered Nov 16 '22 03:11

NikolaiDante


You're not missing anything - there isn't a pop-up window.

The list of issues in the output window is pretty much all you'd get in FxCop. It's just that FxCop is a standalone application.

Here's a decent article on FxCop and Code Analysis:

http://geekswithblogs.net/sdorman/archive/2008/08/19/visual-studio-and-code-analysis.aspx

like image 31
Joe Ratzer Avatar answered Nov 16 '22 02:11

Joe Ratzer


Just so everyone knows, because it took me a long time to figure this out.... Code Analysis / FxCop is only included in Team System and Team Suite versions of VS 2008, not in the Professional Edition.

like image 27
Chris Ammerman Avatar answered Nov 16 '22 03:11

Chris Ammerman


An alternative to FxCop would be to use the tool NDepend that lets write Code Rules over C# LINQ Queries (namely CQLinq). NDepend is integrated in VS 2012, 2010 and 2008. Disclaimer: I am one of the developers of the tool

More than 200 code rules are proposed by default. Customizing existing rules or creating your own rules is straightforward thanks to the well-known C# LINQ syntax.

NDepend code rules can be verified live in Visual Studio and at build process time, in a generated HTML+javascript report.

You seems concerned by the number of false-positive. To keep the number of false-positives low, CQLinq offers the unique capabilities to define what is the set JustMyCode through special code queries prefixed with notmycode. More explanations about this feature can be found here. Here are for example two notmycode default queries:

  • Discard generated and designer Methods from JustMyCode
  • Discard generated Types from JustMyCode

To keep the number of false-positives low, with CQLinq you can also focus rules result only on code added or code refactored, since a defined baseline in the past. See the following rule, that detect methods too complex added or refactored since the baseline:

warnif count > 0 
from m in Methods
where m.CyclomaticComplexity > 20 &&
      m.WasAdded() || m.CodeWasChanged()
select new { m, m.CyclomaticComplexity }
like image 29
Patrick from NDepend team Avatar answered Nov 16 '22 04:11

Patrick from NDepend team