26.04.2015 Views

Team Development with Visual Studio Team Foundation Server

Team Development with Visual Studio Team Foundation Server

Team Development with Visual Studio Team Foundation Server

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

example policy ensures that developers supply check-in comments whenever they check<br />

in a file.<br />

Before You Begin<br />

Note that, to create a check-in policy, you must have the Manipulate security settings<br />

permission set to Allow.<br />

Summary of Steps<br />

• Step 1 – Create and Build a Custom Policy Class<br />

• Step 2 – Register the Custom Policy in the Windows Registry<br />

• Step 3 – Apply the Custom Policy<br />

• Step 4 – Validate the Custom Policy<br />

Step 1 – Create and Build a Custom Policy Class<br />

In this initial step, you create a custom policy class by deriving from the PolicyBase base<br />

class in the Microsoft.<strong>Team</strong><strong>Foundation</strong>.VersionControl.Client namespace. By<br />

deriving from this base class, your class implements the IPolicyDefinition and<br />

IPolicyEvaluation interfaces. The example policy code below forces a developer to<br />

supply check-in comments whenever he or she checks in a source file.<br />

1. Use <strong>Visual</strong> <strong>Studio</strong> to create a new <strong>Visual</strong> C#® class library project.<br />

2. Add an assembly reference to System.Windows.Forms.dll. You use this assembly to<br />

display message boxes.<br />

3. Add an assembly reference to<br />

Microsoft.<strong>Team</strong><strong>Foundation</strong>.VersionControl.Client.dll. By default, this is installed<br />

in the following folder:<br />

\Program Files\<strong>Visual</strong> <strong>Studio</strong> 2005 <strong>Team</strong> <strong>Foundation</strong> <strong>Server</strong>\Tools<br />

4. Replace your skeleton class code implementation <strong>with</strong> the following source. Note that<br />

the class derives from the PolicyBase base class and is marked as serializable.<br />

using System;<br />

using System.Windows.Forms;<br />

using Microsoft.<strong>Team</strong><strong>Foundation</strong>.VersionControl.Client;<br />

[Serializable]<br />

public class CheckForCommentsPolicy : PolicyBase<br />

{<br />

public override string Description<br />

{<br />

get { return "Remind users to add meaningful comments to their checkins"; }<br />

}<br />

// This is a string that is stored <strong>with</strong> the policy definition on the source<br />

// control server. If a user does not have the policy plug-in installed, this string<br />

// is displayed. You can use this to explain to the user how they should<br />

// install the policy plug-in.<br />

public override string InstallationInstructions<br />

{<br />

get { return "To install this policy, read InstallInstructions.txt."; }<br />

}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!