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 http://www.microsoft.com/en-gb/download/details.aspx?id=8279
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.
- Open your project
- Right button on project and select properties
- Select Code Analysis
- 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="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration><!-- Insert your XML code in here-->
Set code analysis to run every time I build my project
<RunCodeAnalysis>Always</RunCodeAnalysis>
I do not want to run code analysis on generated code
(this can be done in properties of project using properties of project)
and error list will be<CodeAnalysisIgnoreGeneratedCode>true</CodeAnalysisIgnoreGeneratedCode>
I want the build to fail if project has missing rules
Indicates if the code analysis should fail if rule set is missing<CodeAnalysisFailOnMissingRules>true</CodeAnalysisFailOnMissingRules>
Treat warnings as errors
This will not display any warnings in error list<CodeAnalysisTreatWarningsAsErrors>false</CodeAnalysisTreatWarningsAsErrors>This will get one error in Error List tab<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
And result in your error list will be:
Another additional information about FxCop and MS Build
http://www.paraesthesia.com/archive/2010/03/29/updating-your-continuous-integration-build-to-run-fxcop-from-vs2010.aspx
No comments:
Post a Comment