The idea behind the Custom Path Policy is to enable the application or exclusion of source control policies to a specific portion or portions of your source control tree. The Custom Path Policy is part of the Team Foundation Server Power Tools, and can be downloaded for free from the Microsoft Web site.
Let's say you enable the Code Analysis check-in policy on your team project. All is great and the developers are checking in some wonderful code. Unfortunately for the QA team, this also means that Code Analysis is being run on their unit tests, where it isn't really needed (arguably).
The solution would be to create a Custom Path Policy to exclude the unit tests directory from the Code Analysis policy by using the following steps:
- Open the Team Explorer tool window in Visual Studio
- Right-click on your team project, and select Team Project Settings | Source Control…
- Click to the Check-in Policy tab
- Click Add…
- Select Custom Path Policy and click OK
- In the Select Child Policy dropdown, select the policy for which the Custom Path Policy should apply. Note, if you just added the child policy, it may not show up in the dropdown until you close and re-open the Source Control Settings dialog. In our case, we would select the Code Analysis policy.
Next, we must define the regular expressions which act as source control path filters. I personally use Expresso (here and here) to work with regular expressions and find it quite handy though your mileage may vary. Here are some path filter examples:
Apply the policy to all C# source files, except under the UnitTests directory:
^((?!.*(/UnitTests/)).)*\.cs$
Apply the policy to all C# source files, except under the UnitTests and Archive directories:
^((?!.*(/UnitTests/|/Archive/)).)*\.cs$
Apply the policy only to a specific directory:
.*/Path/To/Specific/Directory/.*
Note, trying to enter an invalid regular expression filter results in the following dialog:
It is also important to note that when entering multiple regular expression filters, they are joined using OR under the covers as in (regex 1 OR regex 2 OR BOTH). This is important when trying to specify a project and a file type, and means that you should express both in the same expression.
Now that the regular expressions are set up, we can finish up with our custom path policy:
- Once the filters are defined, click OK
You will be presented with the following dialog, which may be somewhat ambiguous:
This means that you need to disable the original policy, which in our case is the Code Analysis policy, or it will be run twice: once by itself and once as part of the Custom Path policy.
- Click OK to close the message box
- Select the original policy, in our example the Code Analysis policy, and click the Disable button