我在我的本地项目的文件位于我的硬盘的文件夹的全名。现在我需要从TFS服务器获取该项目的最新相应文件。TF命令行工具:比较本地的源文件与搁置TFS文件
我的目标是获取两个版本和(使用C#)对它们进行比较。
什么是通过微软的TF命令行工具来获得这些文件的最好方法?
我在我的本地项目的文件位于我的硬盘的文件夹的全名。现在我需要从TFS服务器获取该项目的最新相应文件。TF命令行工具:比较本地的源文件与搁置TFS文件
我的目标是获取两个版本和(使用C#)对它们进行比较。
什么是通过微软的TF命令行工具来获得这些文件的最好方法?
你正在尝试做什么可能已作为folderdiff
命令内置到tf.exe
。这将向您显示本地源代码树与服务器上最新版本之间的区别。例如:
tf folderdiff C:\MyTFSWorkspace\ /recursive
此功能在Visual Studio和Eclipse中的TFS客户端中也存在。简单地浏览到源代码控制管理的路径,并选择“比较对象......”这就是说,这当然是有。如果这不是你虽历经说得很是什么,为什么这将有
外面有用,我会建议而不是试图编写脚本tf.exe
,而是使用TFS SDK直接与服务器交谈。虽然它很容易与get
的tf.exe
最新版本(更新您的工作文件夹),它是不容易将文件下载到临时位置进行比较。
使用TFS SDK是既强大又非常简单。您应该能够连接到服务器并相当容易地下载临时文件。此代码片段未经测试,并假定您的工作空间映射为folderPath
,您希望与服务器上的最新版本进行比较。
/* 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's 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 */
提前致谢!请给我一些时间来评估。 – RolandK 2012-03-26 08:48:31
等等...你想用C#还是使用命令行客户端来做到这一点? – 2012-03-23 12:05:57
我想过从我的C#工具调用TF。所以,基本上都是。 – RolandK 2012-03-23 12:11:47