rhe1980
rhe1980

Reputation: 1577

TFS2010: Prevent check-in if code analysis warning exists

In my team I want to prevent developer to check-in code with warnings from code analysis.

Like I found in some blogs and stackoverflow-questions I tried to make this with a check-in policy:

  1. Enable Code Analysis in Visual Studio Project and set the Rulset (Microsoft Minimum Recommended Rules)
  2. Add Check-in Policy "Code Analysis" and set the same Ruleset (Microsoft Minimum Recommended Rules).

The Problem now I have is, that the policy only prevent checkin if there are errors, but not if there are only warnings. Of course I can change the ruleset and set all rules as errors. But then also local builds are not possible.

So, what I want is that that the rules all are warnings and building the project is possible but check-in is prevented also if only warning exists.

My idea was, to set a different ruleset in checkin policy settings (same rules but all rules as error). But by trying check-in y get the error: Code analysis settings are not compatible with code analysis policy.

So my question is, if somebody has a solution or idea how I can solve this problem.

Thanks in advance for your answer!

Upvotes: 2

Views: 2350

Answers (2)

vjm
vjm

Reputation: 21

I tried this in V2010 (that is, treat warnings as errors) but it only worked for compiler warnings, not CA warnings. So my CA warnings still remained as warnings whereas my compiler warnings now became errors.

Upvotes: 2

pantelif
pantelif

Reputation: 8544

If I get it right the behavior you after after is :

  • In the developer's workstation: Compiling is successful even if there are warnings
  • In the TFS-Build: Compiling breaks if there are warnings

In order to get this:

  1. Remove the "Enable Code Analysis on Build" from your csproj
  2. Remove the check-in policy
  3. Open your build definition for editing & navigate to "Process">"2.Basic" and set "Perform Code Analysis" to "Always"

Now, be careful that you may run in a situation, where build succeeds in every DEV-workstation & fails in TFS. That would be really bad.
One way to avoid this, is to change your build's Trigger into "Gated Check-in", so that if there are warnings - build will fail & developers can't check in.
This last step, is -in some way- a replacement for the check-in policy you removed.

Upvotes: 1

Related Questions