How To Create Custom Check-In Policy
Create a new Visual C# class library project.
Add an assembly reference to System.Windows.Forms.dll. You use this assembly to display message boxes.
Add an assembly reference to Microsoft.TeamFoundation.VersionControl.Client.dll. By default, this is installed in the following folder:\Program Files\Visual Studio 2008 Team Foundation Server\Tools
Replace your skeleton class code implementation with the following source. Note that the class derives from the PolicyBase base class and is marked as serializable.
Implement abstract class for ‘PolicyBase’
This is a string that is stored with the policy definition on the source control server. If a user does not have the policy plug-in installed, this string is displayed.
You can use this to explain to the user how they should install the policy plug-in.
This string identifies the type of policy.
It is displayed in the policy list when you add a new policy to a Team Project.
This string is a description of the type of policy. It is displayed when you select the policy in the Add Check-in Policy dialog box.
This method is called by the policy framework when you create a new check-in policy or edit an existing check-in policy.
You can use this to display a UI specific to this policy type allowing the user to change the parameters of the policy.
This method performs the actual policy evaluation. It is called by the policy framework at various points in time
when policy should be evaluated. In this example, the method is invoked when various asyc events occur that may have invalidated the current list of failures.
This method is called if the user double-clicks on a policy failure in the UI. In this case a message telling the user to supply some comments is displayed.
This method is called if the user presses F1 when a policy failure is active in the UI. In this example, a message box is displayed.
The Full Code:
Register your custom Checkin Policy :
- Start Regedit.exe and locate the following key HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\9.0\TeamFoundation\SourceControl\Checkin Policies
The registered policies are listed in the right pane.
- Right-click in the right-hand pane, point to New, and then click String Value.
- Type the name of your custom policy dynamic link library (DLL), without the DLL extension; Custom Checkin Policy in the above example.
Important: The new string name must match your DLL filename exactly, without the DLL extension.
- Double-click the new string value and set its value to the fully qualified path and filename to the .dll containing your custom policy.
Now you can add your new check-in policy to Team Project.