How to delete test cases from Team Foundation Serv

2019-02-20 13:05发布

How do you go about deleting test cases from Team Foundation Server? I have taken the following stesp:

  • First I installed Team Foundation Server Power Tools from this website.

  • Second I entered the following into the VS command window: witadmin destroywi /collection: server name /id: test case id

I received the following error message from the VS command prompt: Command "witadmin" is not valid.

I even tried to run this command from the windows command prompt as a normal user and also selecting "Run as administrator", however in each case I get the same error message stating "Command "witadmin" is not valid"...

1条回答
Fickle 薄情
2楼-- · 2019-02-20 13:38

witadmin is not part of TFS Power Tools and should be available from the Visual Studio Command Prompt on the default instalation of Visual Studio and Team Explorer.

If for any reason it isn't available, you should be able to find it at "c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE" or an equivalent path in case Visual Studio was installed elsewhere.

There shouldn't be any spaces between the parameter name and the parameter itself and multiple IDs can be specified by delimiting them with commas:

witadmin destroywi /collection:host\collection /id:3,5,7

EDITED to include new requirements from the OP

If you need more flexibility in determining what work items are to be destroyed, you should resort to Team Foundation's client API. In the sample below, I created a console application that receives two parameters: The Team Project's name and a WIQL query:

using System;
using System.Linq;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace DelWi {
    class Program {
        static void Main(string[] args) {
            var store = new WorkItemStore(args[0]);
            WorkItemCollection workItems = store.Query(args[1]);
            if (workItems.Count == 0) {
                Console.WriteLine("No work items with the specified criteria.");
            }
            var query = from workItem in workItems.Cast<WorkItem>()
                        select workItem.Id;
            foreach (var item in store.DestroyWorkItems(query)) {
                Console.WriteLine("{0}\t{1}", item.Id, item.Exception.Message);
            }
            Console.WriteLine("Press any key to continue...");
            Console.Read();
        }
    }
}

Once compiled you can call it passing the parameters such as in:

DelWi.exe "host\defaultcollection" "SELECT * FROM WorkItems WHERE [System.TeamProject] = 'The Best Team Project Ever'  AND  [System.WorkItemType] = 'Test Case'  AND  [System.Id] > 34  AND  [System.Id] < 37"

Be careful though, because if you don't specify the query correctly you may end up deleting more work items than you want.

查看更多
登录 后发表回答