Search code examples
c#tfscheckin-policy

TFS 2013 Custom Check in Policy


I'm trying to implement a custom policy for a specific team project (projectA). However when I implement this in the context of projectA, it evaluates for every file in the included check ins. Say I have a check in for ProjectB larger than 1MB. It will evaluate for this even though it is not in the context of the currently policy, projectA. How can I adjust this so that it will only evaluate for the current project.

public override PolicyFailure[] Evaluate()
{
    foreach (PendingChange pc PendingCheckin.PendingChanges.CheckedPendingChanges)
    {
        FileInfo file = new FileInfo(pc.LocalOrServerItem.ToString());
        if (file.Length > 1048576)
        {
            return new PolicyFailure[] { new PolicyFailure("File size exceeds 1 MB. The size of the file is: " + file.Length.ToString() + " Bytes.", this) };
        }
    }
    return new PolicyFailure[0];
}

Registry key I'm using:

[$RootKey$\TeamFoundation\SourceControl\Checkin Policies]
"TeamFoundation.Samples.CheckFileSizePolicy"="$PackageFolder$\CheckFileSizePolicy.dll"

Solution

  • If the custom check in policy works well, you just need to use Custom Path Policy. Just like the description mentioned: This policy scopes other policies to specific folders or file types.

    Note: TFS 201X Power Tools is needed.

    Detail steps about how to use this, you can refer this link: TFS 2010 : How to apply check-in policies to only certain branches or folders