Nasseh
Nasseh

Reputation: 439

How to use configuration in TFS check-in policy?

Let's say that you're creating a policy to restrict the LOC (line of code) of each code file to some X number.

Now you want to deploy that policy for two teams, and for each team you want X to be a different number.

How will you do that?

My current code is something like:

if (loc > 500)
{
   // returning invalid LOC message
}

AMAIK, config files can't be used with TFS custom check-in policies.

Upvotes: 2

Views: 81

Answers (1)

jessehouwing
jessehouwing

Reputation: 115047

The Check-in Policy itself is serialized and the serialized object is stored. So if you make sure your Check-in policy implements ISerializable and that the configuration you want to store is saved to a field or property with the right attributes, then it should be saved when the Policy is set.

You need to implement the Edit method and set the CanEdit property to true. In the Edit method you can show your own editor built using Windows Forms or WPF.

You can find an example check-in policy that has configuration and an editor here:

One thing to remember is that a Check-in policy is activated at the Team project level. In case you have multiple teams in the same team project you need to use the TFS Power Tools' Custom path policy.

With it you can limit a Check-in policy to a specific Source Control path:

enter image description here

Note: In general I find it more reliable and easier to configure to setup these kinds of quality checks as part of a Continuous Integration build and not try to enforce these items through a checkin-policy. The policies are very specific to TFVC, only execute on the client and require the user to use Visual Studio to perform the check-in.

Upvotes: 2

Related Questions