[英]How to get all work items from tfs via c#
美好的一天!
我嘗試從TFS(2010)的集合中獲取所有WorkItems。 我找到了帶有一些代碼示例的博客 ,但效果不佳:
ICommonStructureService Iss = (ICommonStructureService)projCollection.GetService(typeof(ICommonStructureService));
此行代碼返回錯誤-無法連接到TFS(同一代碼連接良好)。 好的,我嘗試重寫此代碼並嘗試執行此操作(來自msdn的另一個工作示例):
private static String _tfsURI ="http:tfsServer:port/tfsUrl"
static void Main(string[] args)
{
// Connect to Team Foundation Server
// Server is the name of the server that is running the application tier for Team Foundation.
// Port is the port that Team Foundation uses. The default port is 8080.
// VDir is the virtual path to the Team Foundation application. The default path is tfs.
Uri tfsUri = (args.Length < 1) ?
new Uri(_tfsURI) : new Uri(args[0]);
TfsConfigurationServer configurationServer =
TfsConfigurationServerFactory.GetConfigurationServer(tfsUri);
Console.WriteLine("Get the catalog of team project collections \n");
// Get the catalog of team project collections
ReadOnlyCollection<CatalogNode> collectionNodes = configurationServer.CatalogNode.QueryChildren(
new[] { CatalogResourceTypes.ProjectCollection },
false, CatalogQueryOptions.None);
// List the team project collections
foreach (CatalogNode collectionNode in collectionNodes)
{
Console.WriteLine(collectionNode.Resource.DisplayName);
// Use the InstanceId property to get the team project collection
Guid collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]);
TfsTeamProjectCollection teamProjectCollection = configurationServer.GetTeamProjectCollection(collectionId);
ICommonStructureService Iis = (ICommonStructureService)teamProjectCollection.GetService(typeof(ICommonStructureService));
ProjectInfo[] projInfo = Iis.ListAllProjects();
// WorkItemStore wis = (WorkItemStore)teamProjectCollection.GetService();
var wis = (WorkItemStore)teamProjectCollection.GetService(typeof(ICommonStructureService));
foreach (var p in projInfo)
{
Console.WriteLine("Name:" + p.Name + "Status" + p.Status);
var wic = wis.Query(" SELECT [System.Id], [System.WorkItemType]," +
" [System.State], [System.AssignedTo], [System.Title] " +
" FROM WorkItems " +
" WHERE [System.TeamProject] = '" + p.Name +
"' ORDER BY [System.WorkItemType], [System.Id]");
Console.WriteLine("wic.Count:"+wic.Count);
foreach (var wi in wic)
{
Console.WriteLine(wi.Id);
Console.WriteLine(wi.Title);
}
}
// Print the name of the team project collection
Console.WriteLine("Collection: " + teamProjectCollection.Name);
// Get a catalog of team projects for the collection
ReadOnlyCollection<CatalogNode> projectNodes = collectionNode.QueryChildren(
new[] { CatalogResourceTypes.TeamProject },
false, CatalogQueryOptions.None);
// List the team projects in the collection
foreach (CatalogNode projectNode in projectNodes)
{
Console.WriteLine(" Team Project: " + projectNode.Resource.DisplayName);
}
}
Console.ReadLine();
}
因此,我得到了一個錯誤:無法將“ Microsoft.TeamFoundation.Proxy.CommonStructureService”的對象類型轉換為“ Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore”。
請幫我忙,從Tfs獲取所有工作項目。
這條線
var wis = (WorkItemStore)teamProjectCollection.GetService(typeof(ICommonStructureService));
顯然是錯誤的。 解決方法很簡單:
var wis = teamProjectCollection.GetService<WorkItemStore>();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.