in

Platinum Bay

Peace, Love and Visual Studio Team System

.NETicated

From the Forums: Custom Path Policy

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:

  1. Open the Team Explorer tool window in Visual Studio
  2. Right-click on your team project, and select Team Project Settings | Source Control…
  3. Click to the Check-in Policy tab
  4. Click Add…
  5. Select Custom Path Policy and click OK
  6. 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:

  1. Once the filters are defined, click OK
  2. 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.

     

  3. Click OK to close the message box
  4. Select the original policy, in our example the Code Analysis policy, and click the Disable button
Published Mar 07 2008, 10:49 PM by Steve
Filed under:

Comments

No Comments

Leave a Comment

(required )  
(optional )
(required )  
Add

About Steve

Steve Andrews has been working as a developer for more than 8 years. During this time, he has designed and developed applications in such widely varying areas as trust accounting, medical information management, supply chain management, and retail systems. He has firsthand developer experience with a variety of languages, including Java, VB, and .NET. Most recently, he has been immersed in SharePoint. He is currently employed at RDA Corporation in Philadelphia, PA, as a Software Engineer and a team member in the Architectural Guidance evangelism team. Steve is also an MTCS (x2), ICSOO, and .NET fanatic.
Powered by Community Server (Commercial Edition), by Telligent Systems
© Platinum Bay | Some Rights Reserved Creative Commons License

Disclaimer: The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion. Feel free to challenge me, disagree with me, or tell me I'm completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or annonymous comments) - so keep it polite, please.