This project is read-only.

How to enforce coding standards prior to check-in

- J.D. Meier, Jason Taylor, Alex Mackman, Prashant Bansode

Use TFS check-in policies to ensure that all code checked into the server meets your required coding standards.

The following check-in policies are available by default:
  1. Code Analysis – Requires that code analysis be run before check-in.
  2. Test Policy – Requires that check-in tests be completed before check-in.
  3. Work Items – Requires that one or more work items be associated with the check-in.

The default code analysis check-in policy provides code analysis checks for both managed and unmanaged code. Managed code statically analyzes your code to ensure that it conforms to standard .NET design rules, globalization rules, interoperability rules, naming rules, performance rules, security rules, and more. If you need to extend the code analysis, you can develop your own code analysis rules.

To configure the code analysis check-in policy
  1. In Team Explorer, right-click your team project, point to Team Project Settings, and then click Source Control.
  2. Click Check-in Policy and then click Add.
  3. In the Check-in policy list, select Code Analysis and then click OK.
  4. Specify the type of code analysis that you want performed by selecting the appropriate check boxes. If you select Enforce Code Analysis For Managed Code, select the required rules in the Rule settings for Managed Code Analysis list.
  5. Click OK twice.

Important: Although the above procedure ensures that the configured policy is executed whenever a developer checks in a source file, developers can always override policy at check-in time. If you want to monitor this in order to manage this scenario, you can hook the policy override event.

You can create your own custom check-in policies that will enforce your project-specific quality gates; for example, if you want to enforce the following:
  • Users should add comments at the time of check-in.
  • Users should run additional acceptance tests before checking in the code.
  • Users do not use certain pragma directives in C# to suppress XML documentation warnings
  • Ensure that the projects are configured to generate XML documentation during compilation.

To create custom policy plug-ins that will appear in the Add Checkin Policy dialog box, use the extensibility features provided in the Visual Studio Team Foundation Server Software Development Kit (SDK).

Additional Resources

Last edited Jul 31, 2007 at 2:51 PM by prashantbansode, version 10


No comments yet.