views:

1635

answers:

2

I am new to Team Foundation Server and I'm trying to connect to a project programmatically using c#. I have the following block of code ...

string serverName = "http://tfs01:8080";
TeamFoundationServer tfs = new TeamFoundationServer(serverName);
VersionControlServer version = (VersionControlServer)tfs.GetService(typeof (VersionControlServer));
Workspace workspace = version.GetWorkspace("Test", version.AuthenticatedUser);
MessageBox.Show(workspace.Name);

When I execute the code I receive the following error ...

TF14061: The workspace Test;vercuskis does not exist.

The "Test" project is off of the root and is visibile from VS 2008 Team Explorer, I do have security access to it and I use it to check in and out code just fine

I'm not sure if I have the "Test" project referenced correctly within my code. I'm looking for an example of how to reference a project name off of the TFS root.

Thank you,

+2  A: 

The problem is that "Test" in your code above refers to the TFS workspace, not the project in TFS. TFS uses an idea called workspaces that you map directories and projects to.

The workspace you are using is shown in the source control explorer windwo towards the top. It says: 'Workspace: ' and then the name of the workspace you are using.

Here is a good resource regarding workspaces: http://www.woodwardweb.com/teamprise/000333.html

You will then need to probably get some folder mappings from TFS as well. The TFS documentaiton is sparse, and much of the work I have done with it requires some trial and error to understand how TFS works, and how the API is different from using the source control explorer in visual studio.

Brian
Ah ok I see ... well then I guess its not the workspace I'm looking for. I'd like to connect to the project and see all of the items within the source control for that project. I'm guessing I'll have to query the TeamFoundationServer object in order to get into that.
Scott Vercuski
A: 

Like Brian said, you're confused about what a workspace is. His link is a good one: http://www.woodwardweb.com/teamprise/000333.html

If you just want to query history information about the version control system and not checkin/checkout any files, you don't need a workspace at all. Just use the VersionControlServer object.

  • QueryItems = "tf dir"
  • QueryItemsExtended = "tf properties"
  • QueryPendingChanges = "tf status"
  • QueryHistory = "tf history" -- beware, enumeration causes additional server roundtrips via yield return
  • etc etc
Richard Berg