24 May 2006

TFSVC API - Workspace.Get() and GetOptions Enum

I'm writing a console app to do code generation during our Continuous Integration process. To do a Get from TFS Version Control, I'm hitting its managed API, specifically the Workspace object. The Workspace.Get() method has a number of overloads. The one I'm concerned with takes a local or server path and VersionSpec wrapped in a GetRequest object and a GetOptions parameter. I want to force a get in all cases as well as ensure that I will overwrite any existing files on the local file system. Normally I would expect there to be a GetOptions entry for GetAll and Overwrite combined. There isn't, but each of these values does exist on its own within the enumeration. What I did notice is that the values in the enumeration look a lot like bitmask values. GetOptions Enumeration

NameValue
None0
Overwrite1
GetAll2
Preview4
So you can ue bitwise operations to combine these values for use in the Get() operation. The code snippet below will perform the Get() which forces the TFS client to get the file every time and also to overwrite any writable version in the local folder: Dim request as GetRequest request=New GetRequest({local or server path}, VersionSpec.Latest) wkspace.Get(request, _ CType(GetOptions.GetAll + GetOptions.Overwrite, GetOptions)) Since the GetOptions enum is a bitmask you can use the approach above or use a Bitwise-OR to combine these values. wkspace.Get(request, CType(GetOptions.GetAll OR GetOptions.Overwrite, GetOptions))))

2 comments:

Anonymous said...

You can also do a GetOptions.GetAll | GetOptions.Overwrite

Anonymous said...

Thanks Steve - this was helpful.

Post a Comment