Question

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,

Was it helpful?

Solution

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.

OTHER TIPS

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

I had the same issue, i believe it was because the WorkSpace from VS was mapped with multiple projects. So I created a new WorkSpace with only one mapped project.

My worked solution: Open the CMD from VS Run the bellow Line: tf workspace /new /s:http://tfs2010.server.com:8080/tfs

Like this:

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>tf workspace /new /s:http://tfs2010.server.com:8080/tfs

You will be prompted to setup the new WorkSpace: Name: the workspace name you like (no space or special char) Source control folder: $/FolderName Local Folder: C:\FolderName

Use the inputed WorkSpace Name in you're code

    this._server = config.GetAttribute("server");
    **this._workspace = config.GetAttribute("workspace");**
    this._user = config.GetAttribute("user");
    this._password = config.GetAttribute("psw");
    TeamFoundationServer tfs = new TeamFoundationServer(this._server, new System.Net.NetworkCredential(this._user, this._password));
    tfs.Authenticate();
    VersionControlServer versionControl = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
    Workspace ws = versionControl.GetWorkspace(this._workspace, this._user);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top