2

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"
ace
  • 53
  • 1
  • 6

1 Answers1

2

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

Chamberlain
  • 881
  • 5
  • 17
  • 1
    Thanks, this will help quite a bit, I think i've follow other articles on this site about custom policies. Unfortunately this also requires us to have all developers install Power Tools as well as the custom policy so this may not work. Thank you for pointing me in the right direction. – ace Feb 23 '16 at 18:53