Ask a developer for confirmation in a TFS checkin policy

Ask a developer for confirmation in a TFS checkin policy

A TFS checkin policy can normally only be dismissed by overriding the policy. There is no way to selectively allow a user to override one, but not another policy. And there is no way to interact with the user from the Check-in dialog using custom UI other than the message, you can't add your own check box or text box.

One of the policies I recently wrote warns the developer that he might be doing something stupid. We want our developers to be able to dismiss this warning, but we don't want him to override the work item attachment or the comment policy.

So we decided to add a way for the developer to dismiss the warning by double clicking the message.

Edward Thompson confirmed on StackOverflow that interacting with the user on the Evaluate method to be avoided. But the documentation mentions another event, the Activate method, which is called when the user interacts directly with the warning.

This is ideal for this situation. By double clicking the warning, we trigger the Activate method, show a warning and upon dismissal of the dialog save the result.

Now when the conditions for the policy changes, we reset the result and the policy will trigger again.

In order to allow a user to dismiss the policy, we added a configuration option to the policy which will allow this:

A sample UserOverridePolicy can be found on StackOverflow and our Multiple Branches policy implements this strategy as well.

I might even take this as far as allowing any policy to be nested in a generic UserDismissablePolicy in the future, similar to how the Custom Path Policy works.

Source: StackOverflow