private static voID GetLatest(string username,string password,string path_to_download,string tf_src_path) { Uri collectionUri = new Uri(PathConstants.uri); NetworkCredential credential = new NetworkCredential(username,password); TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(PathConstants.uri),credential); tfs.EnsureAuthenticated(); VersionControlServer vc = tfs.GetService<VersionControlServer>(); foreach (var item in vc.GetItems(PathConstants.tfsRoot + tf_src_path,Versionspec.Latest,RecursionType.Full).Items) { string relativePath = _BuildrelativePath(path_to_download,item.ServerItem); switch (item.ItemType) { case ItemType.Any: throw new ArgumentOutOfRangeException("ItemType returned was Any; expected file or Folder."); case ItemType.file: item.Downloadfile(relativePath); break; case ItemType.Folder: Directory.CreateDirectory(relativePath); break; } } }
但是此代码从源下载所有文件并替换本地工作区上的现有文件.
有没有办法只下载本地和服务器版本之间的差异?例如如果我删除本地的任何文件/文件夹,它们也应该与与更改集关联的新文件一起下载,而不替换其他文件
解决方法 这应该更新所有本地工作空间中的所有文件.private static voID GetLatest(string username,string tf_src_path) { Uri collectionUri = new Uri(PathConstants.uri); NetworkCredential credential = new NetworkCredential(username,credential); tfs.EnsureAuthenticated(); VersionControlServer vc = tfs.GetService<VersionControlServer>(); foreach (Workspace workspace in vc.queryWorkspaces(null,null,System.Environment.Machinename)) { foreach (WorkingFolder folder in workspace.Folders) { ItemSpec itemSpec = new ItemSpec(folder.ServerItem,RecursionType.Full); ItemSpec[] specs = new ItemSpec[] { itemSpec }; ExtendedItem[][] extendedItems = workspace.GetExtendedItems(specs,DeletedState.NonDeleted,ItemType.file); ExtendedItem[] extendedItem = extendedItems[0]; foreach (var item in extendedItem) { if (item.VersionLocal != item.VersionLatest) { vc.Downloadfile(item.sourceServerItem,item.Localitem); } } } } }总结
以上是内存溢出为你收集整理的c# – 获取TFS中工作空间的最新和差异全部内容,希望文章能够帮你解决c# – 获取TFS中工作空间的最新和差异所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)