Search code examples
azure-devops-extensions

How to get the Project name with the new azure-devops-extension-sdk?


In the older SDK (vss-web-extension-sdk) - we could use VSS.getWebContext() to get the project name and id. I coudln't find a similar method in the newer SDK (azure-devops-extensions-sdk)

How can I get the project name with the new azure-devops-extensions-sdk?


Solution

  • There are samples azure-devops-extension-sample

    Sample code:

    import * as SDK from "azure-devops-extension-sdk";
    import { CommonServiceIds, IProjectPageService } from "azure-devops-extension-api";
    const projectService = await SDK.getService<IProjectPageService>(CommonServiceIds.ProjectPageService);
    const project = await projectService.getProject();
    

    https://github.com/microsoft/azure-devops-extension-sample/blob/master/src/Samples/Hub/OverviewTab.tsx