C# 使用 GetWorkspace 连接到 Team Foundation Server 工作区
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1125336/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Connecting to a Team Foundation Server workspace using GetWorkspace
提问by Scott Vercuski
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.
我不确定我的代码中是否正确引用了“测试”项目。我正在寻找如何从 TFS 根目录中引用项目名称的示例。
Thank you,
谢谢,
采纳答案by Brian
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.
问题是上面代码中的“测试”指的是 TFS 工作区,而不是 TFS 中的项目。TFS 使用一种称为工作区的想法,您可以将目录和项目映射到该想法。
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
这是关于工作区的一个很好的资源:http: //www.woodwardweb.com/teamrise/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 中使用源代码管理资源管理器的不同之处。
回答by Richard Berg
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/teamrise/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"
- QueryItemsExtended = "tf properties"
- QueryPendingChanges = "tf status"
- QueryHistory = "tf history" -- beware, enumeration causes additional server roundtrips via yield return
- etc etc
- QueryItems = "tf 目录"
- QueryItemsExtended = "tf 属性"
- QueryPendingChanges = "tf 状态"
- QueryHistory = "tf history" -- 注意,枚举会通过yield return导致额外的服务器往返
- 等等等等
回答by Cosmin Antohe
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 映射了多个项目。所以我创建了一个只有一个映射项目的新工作区。
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
系统将提示您设置新的工作区: 名称:您喜欢的工作区名称(无空格或特殊字符) 源控制文件夹:$/FolderName
本地文件夹: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);