Adding a new check-in policy


One question that came up during our Team System migration was
How do we require developer comments on check-in?
Surprisingly, there is no built in code check-in policy that requires developers to add a comment. But it's easy enough to create a new check-in policy with a bit of .NET code.

A boilerplate Team System Policy looks like this:

using System;
using System.Windows.Forms;
using Microsoft.TeamFoundation.VersionControl.Client;

[Serializable]
public class BoilerplatePolicy : PolicyBase
{
    
public override string Description
    {
        
get { return "describes this policy"; }
    }

    
public override string InstallationInstructions
    {
        
get { return "describes how to install this policy"; }
    }

    
public override string Type
    {
        
get { return "friendly display name of policy"; }
    }

    
public override string TypeDescription
    {
        
get { return "describes what this policy does"; }
    }

    
public override bool Edit(IPolicyEditArgs args)
    {
        
// no configuration to save
        return true;
    }

    
public override PolicyFailure[] Evaluate()
    {
        
if (false)
        {
            
return new PolicyFailure[] {
                
new PolicyFailure("describe failure", this) };
        }
        
else
        {
            
return new PolicyFailure[0];
        }
    }

    
public override void Activate(PolicyFailure failure)
    {
        
// provide some winforms UI describing how to fix the policy failure
    }

    
public override void DisplayHelp(PolicyFailure failure)
    {
        
// provide some winforms help UI
    }
}




But a boilerplate policy isn't very interesting. James Manning provided a code sample for the Check for Comments Policy, which I have packaged into a Visual Studio 2005 solution (5 kb).

Once you've compiled CheckForCommentsPolicy.dll, you need to copy it somewhere on the client PC. I copied mine to the c:\test\ folder.

Now we need to edit the registry to let Team System know there's a new policy at that location:
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\TeamFoundation\SourceControl\Checkin Policies]
"CheckForCommentsPolicy"="c:\\test\\CheckForCommentsPolicy.dll"

Once you've copied the .dll and edited the registry, you can now configure the new rule in Team System.

Right-click your project in Team Explorer, then select Team Project Settings, Source Control:



From here, add a new policy on the Check-in Policy tab:


Notice our new check for comments policy appears and can be selected.

Download the Visual Studio 2005 solution (5 kb) containing the CheckForComments policy and try it yourself. Or maybe you want a policy that checks files with regular expression patterns?



posted on Monday, February 27, 2006 3:22 PM by jatwood

Comments

# Requiring a "clean build" prior to check-in

Another question that came up during our Team System migration wasHow do we require developers to only...
Monday, February 27, 2006 4:51 PM by Team System

# Check in Policy to Force Comments in TFS

Jeff Atwood has posted a sample to allow you to implement what has got to be the single most requested check-in policy for Team System, forcing a user to comment their change. His download also contains some good example check-in...
Monday, February 27, 2006 4:57 PM by Martin Woodward

# re: Adding a new check-in policy

Shoot, I meant to mention this in the body of the post: that registry key can be either at HKLM (local machine) or HKCU (current user).
Tuesday, February 28, 2006 11:27 AM by Jeff Atwood

# Managed Code Analysis and Code Complexity

One of the coolest features of the Developer edition of Team System is integrated code analysis. That's...
Tuesday, February 28, 2006 12:37 PM by Team System

# VSTS Links - 03/01/2006

Rob Caron points us to a process guidance print tool. He also talks about TDD in Agitator and Team System....
Wednesday, March 01, 2006 8:23 AM by Team System News

# Team Foundation Server comment checkin policy

Like Jeff Atwood, I was surprised to find that enforcing comments upon checkin is not supported out of...

# re: Adding a new check-in policy

Every time I try to implement this in a library and add the registry key, Team Explorer gives me the error "Assembly is not registered." when I try to add the policy... Any ideas?
Thursday, May 25, 2006 7:51 AM by mfischer

# re: Adding a new check-in policy

So it's not possible to have the server propogate these policies to all it's client pc's?

Thursday, August 03, 2006 6:16 AM by Iwan

# re: Adding a new check-in policy

Calrify please - every developer in the team should do this? I thought policies are set up by administrator on the peoject level...
Tuesday, August 08, 2006 1:00 PM by Laboremus

# re: Adding a new check-in policy - HOW does one add it to the Add Check-in Policy dialogue???

The blog entries with detailed screen shots are great.

In attempting to implement the custom check-in policy I keep stumbling at discovering what needs to be performed to add the created and registered custom check-in policy to the Add Check-in Policy dialogue so that it can be selected for Team Projects. The following extract from the blog has a link to an MSDN page which in turn blithely states the need to download the VSTS SDK as part of the VS SDK which I have done but am not able to discover the relevant part of the SDK which I need or would be helpful.

Once you've copied the .dll and edited the registry, you can now configure the new rule in Team System.

http://msdn2.microsoft.com/en-us/library/ms181281.aspx
Right-click your project in Team Explorer, then select Team Project Settings, Source Control:
Monday, August 14, 2006 10:07 PM by Stephen Smith

# Installing the Check for Comments Check-In Policy


Why doesn't Team System include a "must have comments" policy for check-ins out of the box? I have...
Tuesday, August 22, 2006 4:08 PM by Team System

# Writing Custom Check-in Policies for TFS

A while back Jeff Atwood posted in his blog an amazing post about custom check-in policies. First he...
Wednesday, August 23, 2006 6:36 AM by while(availableTime>0) {

# Check-in policy: Requiring a comment 工具

內建的 TFS Policy 只要求配套 對應的 WorkItem.
實際上對 未導入 WorkItem 作管理的團隊來說 是很可惜的
一直覺得有天 應該會有個 Comments Policy.....
Friday, September 15, 2006 5:59 AM by Refines.Info["Polo Lee"]

# re: Adding a new check-in policy

Forgive me if this is a stupid question. It appears like this policy is only in effect on the client machine, is that true? If so, is there a way to enforce it on the TFS server so the entire team is required to comply with the policy?
Wednesday, September 27, 2006 12:12 PM by don

# Stop, the build is broken!!

It's late, your tired and yet somehow you got stuck fixing the build because junior engineer bob just
Thursday, October 26, 2006 7:24 AM by Clark Sell

# Stop, the build is broken!!

It's late, your tired and yet somehow you got stuck fixing the build because junior engineer bob just
Monday, October 30, 2006 6:54 AM by Clark Sell

# Enforce comments TFS Check-in policy

Use this tool to enforce comments being added by developers when the check-in their code to a tfs source
Tuesday, November 21, 2006 2:07 AM by Merrick Chaffer's Blog

# Enforce comments TFS Check-in policy

Use this tool to enforce comments being added by developers when the check-in their code to a tfs source
Tuesday, December 05, 2006 4:16 AM by Merrick Chaffer's Blog

# clean build check in policy

Do we have any in built policy for clean build check in. As it was there in the earlier versions but now I am not able to find it out in checkin policies dialog box and I read in some blog that it is now integrated in Code Analysis policies but I am not able to find it out there even.
Monday, May 28, 2007 12:15 AM by Krupesh

# Overriding policy failure

I set checkin policy to assossiate work item with the check in. But developer can override policy failure and provide any reason for that. Now what I want is that no one should be able to override check in policy, they have to forcefully follow the policy rules. How can we do that?
Monday, May 28, 2007 12:18 AM by Krupesh