TF Command Line Tool: Compare Local Source Files with TFS Pending Files

I have the full name of the folder on my hard drive where my local project files are located. Now I need to get the latest relevant files for this project from the TFS server.

My goal is to get both versions and compare them (using C #).

What is the best way to get these files using the Microsoft TF command line?

+4
source share
1 answer

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.

 /* Some temporary directory to download the latest versions to, for comparing. */ String tempDir = @"C:\Temp\TFSLatestVersion"; /* Load the workspace information from the local workspace cache */ WorkspaceInfo workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(folderPath); /* Connect to the server */ TfsTeamProjectCollection projectCollection = new TfsTeamProjectCollection(WorkspaceInfo.ServerUri); VersionControlServer vc = projectCollection.GetService<VersionControlServer>(); /* "Realize" the cached workspace - open the workspace based on the cached information */ Workspace workspace = vc.GetWorkspace(workspaceInfo); /* Get the server path for the corresponding local items */ String folderServerPath = workspace.GetServerItemForLocalItem(folderPath); /* Query all items that exist under the server path */ ItemSet items = vc.QueryItems(new ItemSpec(folderServerPath, RecursionType.Full), VersionSpec.Latest, DeletedState.NonDeleted, ItemType.Any, true); foreach(Item item in items.Items) { /* Figure out the item path relative to the folder we're looking at */ String relativePath = item.ServerItem.Substring(folderServerPath.Length); /* Append the relative path to our folder local path */ String downloadPath = Path.Combine(folderPath, relativePath); /* Create the directory if necessary */ String downloadParent = Directory.GetParent(downloadPath).FullName; if(! Directory.Exists(downloadParent)) { Directory.CreateDirectory(downloadParent); } /* Download the item to the local folder */ item.DownloadFile(downloadPath); } /* Launch your compare tool between folderPath and tempDir */ 
+3
source

Source: https://habr.com/ru/post/1403064/


All Articles