使用GetWorkspace连接到Team Foundation Server工作区

时间:2023-01-24 14:05:31

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 ...

我是Team Foundation Server的新手,我正在尝试使用c#以编程方式连接到项目。我有以下代码块...

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

“测试”项目不在根目录下,可以从VS 2008团队资源管理器中访问,我有安全访问权限,我用它来检查和输出代码就好了

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.

我不确定我的代码中是否正确引用了“Test”项目。我正在寻找一个如何从TFS根目录引用项目名称的示例。

Thank you,

3 个解决方案

#1


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.

问题是上面代码中的“Test”是指TFS工作空间,而不是TFS中的项目。 TFS使用一个名为workspaces的想法,您可以将目录和项目映射到。

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.

您正在使用的工作空间显示在源控件资源管理器windwo中。它说:'Workspace:'然后是您正在使用的工作区的名称。

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

这是一个关于工作空间的好资源: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.

然后,您可能需要从TFS获取一些文件夹映射。 TFS文档非常稀疏,我用它完成的大部分工作都需要一些试验和错误来理解TFS的工作原理,以及API与Visual Studio中使用源代码管理资源管理器的不同之处。

#2


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

就像Brian说的那样,你对工作空间是什么感到困惑。他的链接很好: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.

如果您只想查询有关版本控制系统的历史信息而不检查/签出任何文件,则根本不需要工作区。只需使用VersionControlServer对象即可。

  • QueryItems = "tf dir"
  • QueryItems =“tf dir”

  • QueryItemsExtended = "tf properties"
  • QueryItemsExtended =“tf properties”

  • QueryPendingChanges = "tf status"
  • QueryPendingChanges =“tf status”

  • QueryHistory = "tf history" -- beware, enumeration causes additional server roundtrips via yield return
  • QueryHistory =“tf history” - 注意,枚举会通过yield return导致额外的服务器往返

  • etc etc

#3


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.

我有同样的问题,我相信这是因为VS的WorkSpace映射了多个项目。所以我创建了一个只有一个映射项目的新WorkSpace。

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

我的解决方案:从VS打开CMD运行下面的线: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

系统将提示您设置新的WorkSpace:名称:您喜欢的工作区名称(无空格或特殊字符)源控制文件夹:$ / FolderName本地文件夹:C:\ FolderName

Use the inputed WorkSpace Name in you're code

在您的代码中使用输入的WorkSpace名称

    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);

#1


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.

问题是上面代码中的“Test”是指TFS工作空间,而不是TFS中的项目。 TFS使用一个名为workspaces的想法,您可以将目录和项目映射到。

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.

您正在使用的工作空间显示在源控件资源管理器windwo中。它说:'Workspace:'然后是您正在使用的工作区的名称。

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

这是一个关于工作空间的好资源: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.

然后,您可能需要从TFS获取一些文件夹映射。 TFS文档非常稀疏,我用它完成的大部分工作都需要一些试验和错误来理解TFS的工作原理,以及API与Visual Studio中使用源代码管理资源管理器的不同之处。

#2


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

就像Brian说的那样,你对工作空间是什么感到困惑。他的链接很好: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.

如果您只想查询有关版本控制系统的历史信息而不检查/签出任何文件,则根本不需要工作区。只需使用VersionControlServer对象即可。

  • QueryItems = "tf dir"
  • QueryItems =“tf dir”

  • QueryItemsExtended = "tf properties"
  • QueryItemsExtended =“tf properties”

  • QueryPendingChanges = "tf status"
  • QueryPendingChanges =“tf status”

  • QueryHistory = "tf history" -- beware, enumeration causes additional server roundtrips via yield return
  • QueryHistory =“tf history” - 注意,枚举会通过yield return导致额外的服务器往返

  • etc etc

#3


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.

我有同样的问题,我相信这是因为VS的WorkSpace映射了多个项目。所以我创建了一个只有一个映射项目的新WorkSpace。

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

我的解决方案:从VS打开CMD运行下面的线: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

系统将提示您设置新的WorkSpace:名称:您喜欢的工作区名称(无空格或特殊字符)源控制文件夹:$ / FolderName本地文件夹:C:\ FolderName

Use the inputed WorkSpace Name in you're code

在您的代码中使用输入的WorkSpace名称

    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);