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?