问题
I'm writing a custom check-in policy in Visual Studio 2010 using C#. I've extended the class PolicyBase and overriden the Evaluate() method so that I can check the user's check-in comment contains specific information. I'm getting the user's check-in comment using this.PendingCheckin.PendingChanges.Comment
What I would like to be able to do is pull out the changeset number that will be assigned to the check-in. Where and how would I get this number?
I'm guessing the Evaluate method is the wrong place because the changeset has been committed at that point and thus the changeset number cannot be determined.
TIA
回答1:
You cannot do this with any degree of certainty with a check-in policy, as they are only evaluated pre-checkin. The server assigns you the changeset when you do the checkin.
You could try to deduce the next changeset number by querying history on $/ (with a limit of 1 history item returned). But obviously you will have a race condition if you depend on this value - someone could easily beat you to the next checkin, thus taking the number you think will be next.
That said, you can get data about check-ins outside of the check-in policy framework. You can either hook up a CommitCheckin event to an instance of Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer, or you can hook up an alert that will notify you when a check-in occurs.
来源:https://stackoverflow.com/questions/7878027/team-foundation-server-getting-the-changeset-id-from-policybase-object