As I noted in http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1475094&SiteID=1 I think there is a bug in EvaluateCheckin with respect to checkin notes. Even if you set a checkin note as required, EvaluateCheckin does not add to NoteFailures for it if you pass in null or an empty string.
To reproduce:
- In a TFS project's source control properties, remove all but the 'Code Reviewer' checkin note and make this required
- Check a file out in your workspace and make a change to it
- Create a C# console app and paste the below code in:
using
System;using
System.Collections.Generic;using
System.Text;// Microsoft.TeamFoundation.VersionControl.Client.dll
using
Microsoft.TeamFoundation.VersionControl.Client;// Microsoft.TeamFoundation.Client.dll
using
Microsoft.TeamFoundation.Client;
namespace
NotesTest{
class Program{
private static string _strWorkspaceLocation = @"C:\YourWorkspace"; private static string _strTeamFoundationServer = "http://TfsServer:8080/";
static void Main(string[] args)
{
// Get a reference to the TFS Server
TeamFoundationServer objTfsServer = new TeamFoundationServer(_strTeamFoundationServer);
// Get a reference to the version control server
VersionControlServer objVersionControl = (VersionControlServer)objTfsServer.GetService(typeof(VersionControlServer));
// Get a reference to the workspace
Workspace objWorkspace = objVersionControl.GetWorkspace(_strWorkspaceLocation);
// Create a checkin notes object to pass into EvaluateCheckin
CheckinNoteFieldValue objCheckinNoteValue = new CheckinNoteFieldValue("Code Reviewer", ""); CheckinNoteFieldValue[] objCheckinNoteValues = new CheckinNoteFieldValue[1];objCheckinNoteValues[0] = objCheckinNoteValue;
CheckinNote objNote = new CheckinNote(objCheckinNoteValues);
// Make sure we have pending changes
if (objWorkspace.GetPendingChanges().Length == 0){
Console.WriteLine("No pending changes to test with");}
else{
// Evaluate the pending checkin CheckinEvaluationResult objResult = objWorkspace.EvaluateCheckin(CheckinEvaluationOptions.Notes,objWorkspace.GetPendingChanges(), objWorkspace.GetPendingChanges(),
"Test comments", objNote, null);
// See if we have any notes failure
if (objResult.NoteFailures.Length == 0){
Console.WriteLine("No Notes failures!");}
else{
Console.WriteLine("Note failure found:"); Console.WriteLine(objResult.NoteFailures[0].Message);}
}
Console.WriteLine(); Console.WriteLine("Press return to close"); Console.ReadLine();}
}
}
Change the location to your workspace mapping and TFS server at the top and execute the code. You can see that no checkin note failures are returned, even if you change the note's empty string value to null.
Could someone confirm this I may, of course, be going mad or doing something stupid!