摘要:TFS 2010 SDK 範例(1)--使用ASP.NET程式讀取工作項目
通常 存取工作項目都是使用內建的TFS介面 如: Team Explorer, Web Access 或者 Test Manager
但是 如果有需要自行撰寫TFS客戶端 應該如何做呢?
通常必須使用VS 2010 和 VS 2010 SDK 來開發
必須先安裝 VS 2010 然後下載 VS 2010 SDK(下載) 並且安裝
安裝完畢後即可開始撰寫ASP.NET網頁
範例程式碼:DemoTFSShowWorkItem.7z
以下是程式碼說明:
首先: 先參考以下組件:
Microsoft.TeamFoundation.Client
Microsoft.TeamFoundation.WorkItemTracking.Client
先從web.config 讀取相關參數並且建立NetworkCredential 物件
NetworkCredential tfsCredential = new NetworkCredential(
WebConfigurationManager.AppSettings["TFSAccount"].ToString(),
WebConfigurationManager.AppSettings["TFSAccountPassword"].ToString(),
WebConfigurationManager.AppSettings["TFSDomainName"].ToString());
然後 取得TfsTeamProjectCollection 物件
Uri tfsCollectionUrl = new Uri(WebConfigurationManager.AppSettings["TFSCollectionPath"].ToString());
TfsTeamProjectCollection tfsCollection = new TfsTeamProjectCollection(tfsCollectionUrl, tfsCredential);
接著就可以取得 WorkItemStore 物件
取得WorkItemStore以後就可以使用GetWorkItem方法讀取workitem了
// Get the work item with the Id
WorkItem wi = wiStore.GetWorkItem(System.Convert.ToInt32(WebConfigurationManager.AppSettings["TfsWorkItemId"]));
// Write the name and value for all fields in the work item
foreach (Field fd in wi.Fields)
{
//Console.WriteLine("{0}: {1}", fd.Name, fd.Value);
string itemValue = "";
if(fd.Value!= null)
{
itemValue = fd.Value.ToString();
}
ListItem currentWorkItemFeild = new ListItem(fd.Name + ":" + itemValue, itemValue);
lstWorkItemFeildValue.Items.Add(currentWorkItemFeild);
}
詳細的TFS SDK 參考資訊請參考以下MSDN網址:
http://msdn.microsoft.com/pt-br/library/bb130146(en-us).aspx
20130620 update:
以下是更多的SDK範例:
http://geekswithblogs.net/TarunArora/category/12804.aspx
風來疏竹,風過而竹不留聲;雁度寒潭,雁去而潭不留影。故君子事來而心始現,事去而心隨空。