4

hereから取得したこのコードを使用したため、ローカルワークスペースとTFSのserverionバージョンの違いとともに最新の変更を取得したい

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

ただし、このコードはソースからすべてのファイルをダウンロードし、ローカル ワークスペースの既存のファイルを置き換えます。

ローカル版とサーバー版の違いだけをダウンロードする方法はありますか? たとえば、ローカルのファイル/フォルダーを削除した場合、他のファイルを置き換えることなく、変更セットに関連付けられた新しいファイルと一緒にそれらもダウンロードする必要があります

4

1 に答える 1

1

これにより、すべてのローカル ワークスペース内のすべてのファイルが更新されます。

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);
                        }
                    }
                }
            }
        }
于 2016-03-31T12:27:01.043 に答える