Misha Sloushch
Misha Sloushch

Reputation: 21

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.

Upvotes: 0

Views: 121

Answers (2)

ds19
ds19

Reputation: 3175

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

Upvotes: 0

chief7
chief7

Reputation: 14393

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.

Upvotes: 0

Related Questions