簡體   English   中英

使用GetWorkspace連接到Team Foundation Server工作區

[英]Connecting to a Team Foundation Server workspace using GetWorkspace

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

當我執行代碼時,我收到以下錯誤...

TF14061: The workspace Test;vercuskis does not exist.

“測試”項目不在根目錄下,可以從VS 2008團隊資源管理器中訪問,我有安全訪問權限,我用它來檢查和輸出代碼就好了

我不確定我的代碼中是否正確引用了“Test”項目。 我正在尋找一個如何從TFS根目錄引用項目名稱的示例。

謝謝,

問題是上面代碼中的“Test”是指TFS工作空間,而不是TFS中的項目。 TFS使用一個名為workspaces的想法,您可以將目錄和項目映射到。

您正在使用的工作空間顯示在源控件資源管理器windwo中。 它說:'Workspace:'然后是您正在使用的工作區的名稱。

這是一個關於工作空間的好資源: http//www.woodwardweb.com/teamprise/000333.html

然后,您可能需要從TFS獲取一些文件夾映射。 TFS文檔非常稀疏,我用它完成的大部分工作都需要一些試驗和錯誤來理解TFS的工作原理,以及API與Visual Studio中使用源代碼管理資源管理器的不同之處。

就像Brian說的那樣,你對工作空間是什么感到困惑。 他的鏈接很好: http//www.woodwardweb.com/teamprise/000333.html

如果您只想查詢有關版本控制系統的歷史信息而不檢查/簽出任何文件,則根本不需要工作區。 只需使用VersionControlServer對象即可。

  • QueryItems =“tf dir”
  • QueryItemsExtended =“tf properties”
  • QueryPendingChanges =“tf status”
  • QueryHistory =“tf history” - 注意,枚舉會通過yield return導致額外的服務器往返
  • 等等

我有同樣的問題,我相信這是因為VS的WorkSpace映射了多個項目。 所以我創建了一個只有一個映射項目的新WorkSpace。

我的解決方案:從VS打開CMD運行下面的線: tf workspace /new /s:http://tfs2010.server.com:8080/tfs

像這樣:

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

系統將提示您設置新的WorkSpace:名稱:您喜歡的工作區名稱(無空格或特殊字符)源控制文件夾: $/FolderName本地文件夾: C:\\FolderName

在您的代碼中使用輸入的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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM