FxCop, Visual Studio, VS2008

Integrate FxCop 1.36 & VS 2008

Update: Visual Studio Team System (VSTS) has Code Analysis feature.  It’s not FxCop but it does serve the same purpose and is built using the same engine as FxCop.  Unfortunately I’m working with VS Professional that doesn’t include Code Analysis.

FxCopI was looking for way to integrate FxCop 1.36 with Visual Studio   2008.  I even asked the same question on StackOverflow.  The only answer I got was a link to MSDN article.  I follow direction in the article but wasn’t successful.  I assume that if you have only one project and don’t have a solution it will work for you but it’s not my case.  I have many project in my solution.  However, the MSDN article got me going.  Let me present you my solution of integration.

Create FxCop project using FxCop GUI.

– Save the project file in the same directory where your solution is.
– Project name must be the file name of your solution (including .sln extension).  For example: If your solution file is MySolution.sln, the FxCop project name must be MySolution.sln.FxCop.

FxCop - Name project

Add FxCop to VS External Tools.

In Visual Studio select Tools->External Tools…  You should see the External Tools dialog box.

You must fill following fields:

Title: FxCop
Command: C:\Program Files\Microsoft FxCop 1.36\FxCopCmd.exe
Arguments: /c /p:"$(SolutionDir)\$(SolutionFileName).fxcop" /cXsl:"C:\Program Files\Microsoft FxCop 1.36\Xml\VSConsoleOutput.xsl"
Initial Directory: C:\Program Files\Microsoft FxCop 1.36
Use output window Must be checked

If you install FxCop in different location than C:\Program Files\Microsoft FxCop 1.36, you need to use your own path.


In case you want to grok the switches we use, you can read more about FxCopCmd options.

Run FxCop from Visual Studio.

We are done.  Now we just need to run FxCop.

Tools –> FxCop should analyze your code and because we checked “Use Output window” in External Tools dialog result should appear in VS output window.

FxCop - result

kick it on DotNetKicks.com