Misha Sloushch February 2016

Tfs Can not Get Project Name from Query programmatically using @Project parameter

i'm looking for your help, guys! I want to get Current Project Name from query, using my custom plugin.

Here is my code

WorkItemCollection queryResults = workItemStore.Query("SELECT [System.TeamProject] FROM WorkItems WHERE [System.TeamProject] = '@Project'");

foreach (WorkItem item in queryResults)
{
// SomeCode;
}

So result of Query is empty.. I have no idea why.. If i'm writing real Project Name instead of the '@Project' it's works.. Also i tried to write @Project wihout quotes - also no result.

Answers


chief7 February 2016

You can't use "@Project" in code like this. @Project is only available within a VisualStudio work item query where it can infer the team project based on your currently selected project in the Team Explorer.


ds19 February 2016

You can try this code if your plugin is an WorkItemChangedEventHandler:

WorkItemChangedEvent workItemChange = (WorkItemChangedEvent)notificationEventArgs;
Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem wi = workItemStore.GetWorkItem(workItemChange.CoreFields.IntegerFields[0].NewValue);

string p = wi.Project.Name

Post Status

Asked in February 2016
Viewed 2,282 times
Voted 12
Answered 2 times

Search




Leave an answer