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
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 ? e.g. 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);
}
}
}
}
}