Code Analysis Error in VS2008 (related to FxCop)

Currently we are converting all the solutions of our application from Visual Studio 2005 to Visual Studio 2008. While converting solutions to VS2008 we faced a minor issue. We use VSTS Static Code Analysis for all our projects. After converting the solutions, some of the solutions throws an error if Code Analysis is turned on. Apparently it tries to use FxCop instead of VSTS for Static Code Analysis. Here’ re the details –

Background & Issue:
After converting a VS2005 solution to VS2008 solution sometime while compiling the solution we receive the following Code Analysis error –

MSBUILD : error : Invalid settings passed to CodeAnalysis task. See output window for details.

Code Analysis Complete — 1 error(s), 0 warning(s)
Done building project "Contact.csproj" — FAILED.

========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

The output windows shows the following details –

Compile complete — 0 errors, 0 warnings

Contact -> C:\Test\Dev\RRDevelopment\Development\GE\Contact\bin\Debug\tgtpharm.Modules.Contact.dll

Running Code Analysis…

c:\Program Files\Microsoft Visual Studio 9.0\Team Tools\Static Analysis Tools\FxCop\FxCopCmd.exe  /outputCulture:1033 /out:"bin\Debug\tgtpharm.Modules.Contact.dll.
CodeAnalysisLog.xml" /file:"bin\Debug\tgtpharm.Modules.Contact.dll" /directory:"..\..\Shared Assemblies\Pharmacy Shared Assemblies\Common.Validation" /directory:"..\..\Shared Assemblies\Pharmacy Shared Assemblies\Common.DataAccess" /directory:"..\..\Shared Assemblies\Pharmacy Shared Assemblies\Common.ReferenceData" /directory:"..\..\Shared Assemblies\Pharmacy Shared Assemblies\DomainModel" /directory:"..\..\Shared Assemblies\Third Party\Enterprise Libraries 2.0" /directory:"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727" /directory:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0" /directory:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5" /directory:"..\..\Shared Assemblies\Third Party\AzMan" /directory:"..\..\Shared Assemblies\Pharmacy Shared Assemblies\Common" /rule:"c:\Program Files\Microsoft Visual Studio 9.0\Team Tools\Static Analysis Tools\FxCop\Rules" /ruleid:-Microsoft.Design#CA2210 /ruleid:-Microsoft.Design#CA1005 /ruleid:-Microsoft.Design#CA1032 /ruleid:-Microsoft.Design#CA1014 /ruleid:-Microsoft.Maintainability#CA1502 /ruleid:-Microsoft.Mobility#CA1600 /ruleid:-Microsoft.Mobility#CA1601 /ruleid:-Design Rules#RR1001 /ruleid:-Microsoft.Usage#CA2209 /searchgac /ignoreinvalidtargets /forceoutput /successfile
/ignoregeneratedcode /saveMessagesToReport:Active /timeout:120

Cause of Issue:
The issue happened as Visual Studio was calling FxCop from the "Visual Studio 8" directory instead of "Visual Studio 9.0". Visual Studio should use "Visual Studio 9.0" for performing the Static code analysis tasks instead of using FxCop external tool (this would be evident from the error as the error shows that Visual Studio us calling FxCopCmd.exe tool instead of Visual Studio 9.0)

To fix to issue create an environment variable called "FXCOPDIR" to point to the 2008 instance of Visual Studio.

  1. In Control Panel, open System. The System Properties dialog box appears.
  2. Click the Advanced tab, and then click Environment Variables. The Environment Variables dialog box appears.
  3. Under System variables, click New. The New System Variable dialog box appears.
  4. In the Variable name box, type FxCopDir.
  5. In the Variable value box, enter the location where the Visual Studio 9.0 IDE or devenv is located (typically it’s located at – C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe), and then click OK.
  6. Restart the Visual Studio 9.0 IDE and compile the project once again. This time the project should compile successfully.




Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s