Fxcop Integration in Visual Studio 2005

I had been searching for this from past few months. I got some solutions over this but following are the best I thought.

1. There is a open source add in available for integration of FxCop in VS 2005 Professional edition.

http://fxcopaddin.tigris.org/

2. It seems to have somewhat maual method but it works:

You can create an external tool to run FxCop and put the output in the Output window. To do this, follow these simple steps:

  1. Go to Tools -> External Tools
  2. Click “Add” and fill in the following details

    Title: FxCop
    Command: C:\Program Files\Microsoft FxCop 1.35\FxCopCmd(.)exe
    Arguments:  /c /p:”$(SolutionDir)\$(SolutionFileName).fxcop” /consolexsl:”C:\Program Files\Microsoft FxCop 1.35\Xml\VSConsoleOutput.xsl”
    Initial Directory: C:\Program Files\Microsoft FxCop 1.35
    Check the “Use Output window” checkbox

3. This method is best of the best of all tricks to achive task of Code analysis:

This is almost like the holy grail of static analysis solutions. Everything I have found on the Internet has pretty much said that it wasn’t possible to enable the same type of static analysis that the Visual Studio Team editions have in Visual Studio Professional. In one sense, they are correct. However, it is possible to get 99% of the functionality working.

Disclaimer:

This is neither a supported nor sanctioned solution by Microsoft and involves registry changes as well as additional Microsoft DLLs that are not part of Visual Studio 2005 Professional.

Since I’m not 100% sure on the redistributable concerns of these files, I am not going to make them available as part of this post. I will give step-by-step instructions on how to get this working under the assumption that you already have these files from some other means. All of the files required for this solution are part of Visual Studio Team Edition for Software Developers (and probably part of any of the Team Edition versions).

  • Copy the C:\Program Files\MSBuild\Microsoft\VisualStudio\v8.0\CodeAnalysis folder.
  • Copy the C:\Program Files\Microsoft Visual Studio 8\Team Tools\Static Analysis Tools folder.

These folders should be copied to the same locations on your Visual Studio 2005 Professional system. The simplicity of this approach works because the Microsoft.Common.targets file already includes all of the necessary logic to include the Code Analysis targets file if it exists.

Unfortunately, this only gets us half way there. To complete the picture, we need to make some registry changes. The registry changes are what tell Visual Studio to load the Static Analysis Tools package. It is this package that governs the interaction between Visual Studio and the build process.

The easiest way is to copy the following code into Notepad and save it with a .reg extension. Then you can merge the file into the registry.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\Packages\{72391CE3-743A-4a55-8927-4217541F6517}]
@=”StanPackage”
“InprocServer32″=”C:\\Program Files\\Microsoft Visual Studio 8\\Team Tools\\Static Analysis Tools\\stanpackage.dll”

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\Packages\{72391CE3-743A-4a55-8927-4217541F6517}\SatelliteDll]
@=””
“DllName”=”StanPackageUI.dll”
“Path”=”C:\\Program Files\\Microsoft Visual Studio 8\\Team Tools\\Static Analysis Tools\\”

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\CLSID\{72391CE3-743A-4a55-8927-4217541F6517}]
@=”StanPackage class”
“InprocServer32″=”C:\\Program Files\\Microsoft Visual Studio 8\\Team Tools\\Static Analysis Tools\\stanpackage.dll”
“ThreadingModel”=”Apartment”

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\CLSID\{960d6d3a-0bd3-4afa-a0a6-31f7f2fe3a8e}]
@=”VCRuleSelectionPage class”
“InprocServer32″=”C:\\Program Files\\Microsoft Visual Studio 8\\Team Tools\\Static Analysis Tools\\stanpackage.dll”
“ThreadingModel”=”Apartment”

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\CLSID\{984ae51a-4b21-44e7-822c-dd5e046893ef}]
@=”VSRuleSelectionPage class”
“InprocServer32″=”C:\\Program Files\\Microsoft Visual Studio 8\\Team Tools\\Static Analysis Tools\\stanpackage.dll”
“ThreadingModel”=”Apartment”

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\Services\{dfb40067-f0c3-425f-9936-951a7900a0ac}]
@=”{72391CE3-743A-4a55-8927-4217541F6517}”
“Name”=”SStaticAnalysisService”

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\Services\{AEBE2A87-9063-4B11-95C0-14E48CEC4439}]
@=”{72391CE3-743A-4a55-8927-4217541F6517}”
“Name”=”SFxCopLoggerService”

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\Setup\EDev]
“StanDir”=”C:\\Program Files\\Microsoft Visual Studio 8\\Team Tools\\Static Analysis Tools\\”
“FxCopDir”=”C:\\Program Files\\Microsoft Visual Studio 8\\Team Tools\\Static Analysis Tools\\FxCop\\”
“CodeAnalysisErrorListViolationLimit”=dword:000000c8

Open Visual Studio (if you had Visual Studio open, you will need to restart it) and you will now have the “Code Analysis” tab in your project properties. The only thing this solution does also provide is the ability to select a message in the error list window and create the supression messages for it.

The next steps…

Now that I have proven to myself (and hopefully to you as well) that this works, I see two follow up steps. The first one is that everyone should start petitioning Microsoft to include this capability in the Visual Studio “Orcas” Professional release. I think it is too important for it to be limited to only the more expensive editions of Visual Studio.

The second step is to recreate the Microsoft DLLs so that we are able to have the same level of integration without worrying about redistribution issues. Hopefully, step one will negate the need for this, but just in case it doesn’t a backup plan is always useful.

References:

1. http://fxcopaddin.tigris.org/

2.  http://www.codeproject.com/dotnet/FxCopIntegrateVSNET.asp

3.  http://geekswithblogs.net/sdorman/archive/2007/02/18/106630.aspx

Note: This post’s contains are collected by the resources mentioned above and does not belong to me.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s