Integrate FxCop 1.36 & VS 2008
Posted by Vadim on May 9, 2009
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.
I 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.
Important:
- 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.
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.



Sean Hederman said
Ummm, it’s ALREADY integrated with VS 2008, so there’s actually no call for what you’re doing, which is perhaps why you found so little information.
Simply open up the project Properties page, click on the Code Analysis tab and check the “Enable Code Analysis on Build” checkbox, OR right click on a project in the Solution Explorer and select “Run Code Analysis”.
Vadim said
Sean,
You’re talking about Code Analysis that is part of VS Team System. However, I’m using Visual Studio Professional that missing this feature.
Sean Hederman said
Really? I honestly thought Professional had it. It’s quite shocking that it doesn’t.
Jeff Klawiter said
I haven’t heard but I’m really hoping the move it down to VS 2010 pro. This is one of those must have features for a “professional” developer. I’m still shocked myself that fxCop has such horrible VS Pro integration. StyleCop integrates fully. It’s easy to use and gives warnings and errors that can stop a build. The price point of going from Pro to TS is quite painful and I’ve yet to be able to convince my bosses to pony up.
Peter Smith said
Another factor is that this method does it at the solution level, not the project level. My solution has 39 projects. You do the math. :) I’m both happy to see this version, AND to find that “Run Code Analysis” exists at the project level; I rarely do ANYTHING at the project level (from the perspective of right-clicking and property pages).
Reflective Perspective - Chris Alcock » The Morning Brew #344 said
[...] Integrate FxCop 1.36 & VS 2008 – Vadim Kreynin shows how you can integrate FxCop 1.36 into your Visual Studio 2008 Builds with some simple instructions. [...]
Technology Related Links for May 11th - Jason N. Gaylord's Blog said
[...] Integrate FxCop 1.36 & VS 2008 – Vadim Kreynin (Suggested by Elijah Manor) [...]
Maithree said
I dont get the Use Output Window option enabled.
Abessinierkatze said
I had the same problem,
but the solution ist very easy:
use the FxCopCmd.exe instead of the FxCop.exe
And you will see, the checkbox will be enabled.
Thanks for this tip