Code Analysis Check-in Policy for TFS

FXCOP (a.k.a CodeAnalysis) is a tool that verifies if the code written complies with the appropriate design guidelines.

During compilation FXCOP will warn if detects that the following design guidelines are not being correctly applied:

Each of these items has additional sub items (FxCop rules) that must be configured manually. Each rule is assigned with a severity level that can be “Warning” and “Error”.

The following are considerations we must have to configure the policy properly:

  • As FxCop operates over assemblies we have to compile our projects first. That’s why we need Code-Analysis inspection every time we locally build the application. We will receive warnings and errors at compile time, giving us the possibility to fix them in early stages.

  • Code-Analysis check-in policy enforces that you run code analysis and your build is up to date. It will fail if there are code analysis errors in your project. It passes successfully if you have run code analysis and there are some warnings in the project. http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=570494&SiteID=1

  • To Add Code-Analysis check-in policy you have to do the following:

    1. At the Team Explorer window right-click over the Team Project you want to set the policy.
    2. Team Project Settings à Source Control
    3. At the Check-in policy tab, Add a Code-Analysis policy and configure the rules and its severity levels.

Note: The Code-Analysis settings configured in this stage will be the same code-analysis settings for the projects of the solutions that migrates the policy.

  • Migrate Code-Analysis policy settings to solution (File à SourceControl à) and enable Code Analysis in all projects of the solution (Proj_Properties à Code Analysis).
  • If a change is made in the policy settings and you want to reflect these changes to all of your solution projects, you should have in consideration that only “Warning” to “Error” severity levels will be updated. You won’t see any change if you switched from “Error” to “Warning”. This behavior is not supported in this version. For more info http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=266963&SiteID=1



Leave a Reply