简体   繁体   English

获取TFS中工作空间的最新信息和差异

[英]Get latest and difference between workspaces in TFS

I want to get latest changes along with the difference between local workspace and serverion version from TFS for that I used this code which I got from here 我想获得最新的更改以及TFS的本地工作空间和服务器版本之间的区别,因为我使用了此代码,这是我从这里获得的

     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;
            }
        }
    }

But this code downloads the all the files from source and replaces the existing files on local workspace. 但是此代码从源下载所有文件并替换本地工作区上的现有文件。

Is there any way to download only the difference between the local and server version ? 有没有办法只下载本地和服务器版本之间的差异? eg If I delete any files/folders on my local , they should be downloaded too along with the new files associated with changesets without replacing other files 例如,如果我删除本地的任何文件/文件夹,它们也应该与更改集关联的新文件一起下载而不替换其他文件

That should update all files in all local workspaces. 这应该更新所有本地工作空间中的所有文件。

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 (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);
                        }
                    }
                }
            }
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM