What you are trying to do can already be built into tf.exe as a folderdiff . This will show you the differences between the local source tree and the latest version on the server. For instance:
tf folderdiff C:\MyTFSWorkspace\ /recursive
This functionality also exists in TFS clients in both Visual Studio and Eclipse. Just go to the path in the Source Control Explorer and select βCompare With ...β However, there are certain reasons why it would be useful to have out
If this is not exactly what you need, I would suggest not trying the script tf.exe , but instead use the TFS SDK to communicate directly with the server. While without get latest version with tf.exe (updating the working folder) it is easy to get , it is not easy to upload the file to a temporary place for comparison.
Using the TFS SDK is powerful and fairly simple. You should be able to connect to the server and upload temporary files quite easily. This piece of code is untested and assumes that you have a workspace mapping in folderPath that you want to compare with the latest version on the server.
String tempDir = @"C:\Temp\TFSLatestVersion"; WorkspaceInfo workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(folderPath); TfsTeamProjectCollection projectCollection = new TfsTeamProjectCollection(WorkspaceInfo.ServerUri); VersionControlServer vc = projectCollection.GetService<VersionControlServer>(); Workspace workspace = vc.GetWorkspace(workspaceInfo); String folderServerPath = workspace.GetServerItemForLocalItem(folderPath); ItemSet items = vc.QueryItems(new ItemSpec(folderServerPath, RecursionType.Full), VersionSpec.Latest, DeletedState.NonDeleted, ItemType.Any, true); foreach(Item item in items.Items) { String relativePath = item.ServerItem.Substring(folderServerPath.Length); String downloadPath = Path.Combine(folderPath, relativePath); String downloadParent = Directory.GetParent(downloadPath).FullName; if(! Directory.Exists(downloadParent)) { Directory.CreateDirectory(downloadParent); } item.DownloadFile(downloadPath); }
source share