How to undo checkout programatically

Feb 11, 2014 at 12:20 PM
I have checkout activity which checkouts all AssemblyInfo.cs as below, and later on I'm increasing the AssemblyInfo version number. Now somehow if build get failed due to some existing code issue than I should perform undo checkout instead of checkin.

Could someone help to provide solution on how to undo checkout. Below is my Checkin activity:

Workspace workspace = context.GetValue(this.Workspace);
        var pendingChanges = workspace.GetPendingChanges();
        WorkspaceCheckInParameters wcip = new WorkspaceCheckInParameters(pendingChanges, "Build. ***NO_CI***");
        wcip.Author = @"domain\user";
        wcip.OverrideGatedCheckIn = true; 
        workspace.CheckIn(wcip);
Coordinator
Mar 1, 2014 at 6:16 PM
I would avoid checkin operations to version code - see my old post
Marked as answer by mikeFourie on 3/7/2014 at 2:03 PM
May 1, 2014 at 7:01 PM
I use an undo checkout for my builds. I have builds that produce shared binaries that need to be checked in to TFS so they can be consumed by other solutions.

I had to write a task to undo pending changes, because developers would sometimes work with those binaries and check them out. See my article:
http://www.codeproject.com/Articles/540083/Custom-MSBuild-Task-to-Undo-Checked-out-Binaries-i