79290654

Date: 2024-12-18 09:54:22
Score: 2.5
Natty:
Report link

OK, so I found some code which I have slightly altered to work how I need it.

This is the code I used to establish a connection using a persoanl access token, which I am reading in from an embedded resource file.

static void ConnectWithPAT(string ServiceURL, string PAT)
{
    VssConnection connection = new VssConnection(new Uri(ServiceURL), new VssBasicCredential(string.Empty, PAT));
    InitClients(connection);
}

The InitClients method is as follows (I didn't touch this bit):

static void InitClients(VssConnection Connection)
{
    WitClient = Connection.GetClient<WorkItemTrackingHttpClient>();
    BuildClient = Connection.GetClient<BuildHttpClient>();
    ProjectClient = Connection.GetClient<ProjectHttpClient>();
    GitClient = Connection.GetClient<GitHttpClient>();
    TfvsClient = Connection.GetClient<TfvcHttpClient>();
    TestManagementClient = Connection.GetClient<TestManagementHttpClient>();
}

Then there's a method that executes the WIQL code:

static void RunStoredQuery(string project, string queryPath)
{
    QueryHierarchyItem query = WitClient.GetQueryAsync(project, queryPath, QueryExpand.Wiql).Result;

    string wiqlStr = query.Wiql;

    GetQueryResult(wiqlStr, project);
}

The GetQueryResult method calls another method called RunQueryByWiql - WorkItemQueryResult result = RunQueryByWiql(wiqlStr, teamProject);

static WorkItemQueryResult RunQueryByWiql(string wiqlStr, string teamProject)
{
    Wiql wiql = new Wiql();
    wiql.Query = wiqlStr;

    if (teamProject == "") return WitClient.QueryByWiqlAsync(wiql).Result;
    else return WitClient.QueryByWiqlAsync(wiql, teamProject).Result;
}

I then just use a StreamWriter to write the results out to a CSV file.

Many thanks @gunr2171 for the guidance. I got there in the end.

Cheers

Steve

Reasons:
  • Blacklisted phrase (0.5): thanks
  • Blacklisted phrase (1): Cheers
  • Blacklisted phrase (0.5): I need
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @gunr2171
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: welshsteve147