Reputation: 8452
In my deployment tool I want to check programmatically whether there are updates available for the project which should be deployed somewhere.
The tool should not update the workspace on itself, it's just supposed to warn the user that there is a new version available in the TFS repository.
I tried the following prototypic function to no avail:
public static bool AreWorkspaceAndRepositoryInSync()
{
const string tfsUrl = "http://mytfs:8080/tfs/MyCollection";
const string tfsPath = @"$/Main/MyProject";
const string wsPath = @"C:\DEV\MyProject";
var projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(tfsUrl));
var vcs = projectCollection.GetService<VersionControlServer>();
var workspaceItems = vcs.GetItems(wsPath, RecursionType.Full);
var repositoryItems = vcs.GetItems(tfsPath, VersionSpec.Latest, RecursionType.Full);
var wsNewest = workspaceItems.Items.Max(i => i.CheckinDate);
var repoNewest = repositoryItems.Items.Max(i => i.CheckinDate);
if (wsNewest != repoNewest)
return false;
return true;
}
This function always returns true
. I suspect that VersionControlServer.GetItems(...)
always retrieves the Item
s from the server, hence my comparision actually compares two identical list.
Is there a way to get the local workspace Item
s? Or is there any other way to achieve something similar?
Upvotes: 1
Views: 889
Reputation: 3352
I wouldn't recommend trying to compute it yourself. The best way to do this is to run tf get /preview. That will tell you if there is anything to do but not actually update the workspace. Using the client OM, call Get with VersionSpec.Latest and GetOptions.Preview.
Upvotes: 2