Thursday, 27 December 2012

Finding and Installing FxCop

Finding and Installing FxCop

Searching for FxCop on Microsoft download site get me readme.txt  file only.

FxCop Installation Instructions
1. Download the Microsoft Windows SDK for Windows 7 and .NET Framework 4 version 7.1.
2. Run %ProgramFiles%\Microsoft SDKs\Windows\v7.1\Bin\FXCop\FxCopSetup.exe to install FxCop.

So after search for the install file:
I have found link
And run the setup file, I have redundant 200 MB that I do not need, and still I am not sure that I got all the files. I can uninstall everything when done.

After installation the file I am are looking for is located in :
%ProgramFiles%\Microsoft SDKs\Windows\v7.1\Bin\FXCop folder\

Alternative option is extraction from ISO disk here and download link for Microsoft Windows SDK for Windows 7 and .NET Framework 4 (ISO) here

Now we have installed FxCop.

You can run it on your system from your installation location.
 (default on my system is :"C:\Program Files (x86)\Microsoft Fxcop 10.0\FxCop.exe")

Lets try to use it in our VS 2012 solution.

I have created throw-away project where I have setup the project.
To switch FxCop on you need to do just simple steps.

  1. Open your project
  2. Right button on project and select properties
  3. Select Code Analysis
  4. Check checkbox nexto:  Enable Code Analysis on Build

This sets code analysis on build.
I have created my own rule set to have one specific for my projects.

Update Project file

I wanted to set custom conditions to my project. For this I had to update my project file, where is my code analysis running.

See comment in green highlighted code below.

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
      <!-- Insert your XML code in here-->

Set code analysis to run every time I build my project


I do not want to run code analysis on generated code 

(this can be done in properties of project using properties of project)

I want the build to fail if project has missing rules
Indicates if the code analysis should fail if rule set is missing


Treat warnings as errors

This will not display any warnings in error list
This will get one error in Error List tab

And result in your error list will be:

and error list will be

Another additional information about FxCop and MS Build

No comments:

Post a Comment