user13812143
user13812143

Reputation:

How to get list of all projects with versions in the azure DevOps server from WPF or Windows application

I want to list and display all project files in Azure DeveOps server from a windows/WPF application. Ealier My application retrieve data from TFS server. Now our repository is changed and Now Azure devops server is used instead of TFS. I am looking for equivalent of below code which is used in TFS. I want to do same operation with Azure DevOps Server.

Sample Code to get all project files and objects from TFS

 Uri tfsUri;            
        string OutPutFolderDB, DirectoryNextTo, Path;
        tfsUri = new Uri("http://" + serverURI + "/testProjectCollection");
        var targettfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tfsUri);
        Microsoft.TeamFoundation.Server.ICommonStructureService stuctureService =
       targettfs.GetService<Microsoft.TeamFoundation.Server.ICommonStructureService>();

        Microsoft.TeamFoundation.Server.ProjectInfo[] projects = stuctureService.ListAllProjects();
        VersionControlServer vcs = targettfs.GetService<VersionControlServer>();

I would like to know similar kind of above code which is used in Azure devops server. My repository is git.

Upvotes: 1

Views: 7374

Answers (2)

Hendrick Castro
Hendrick Castro

Reputation: 11

If you want download all these:

click here

Upvotes: 0

Vito Liu
Vito Liu

Reputation: 8298

We recommend that you can use REST API to list all projects in the power shell script.

Sample:

$connectionToken="{PAT}"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))
$OrgUrl = "https://dev.azure.com/{Org name}/_apis/projects?api-version=6.0-preview.4" 
$ListProject = (Invoke-RestMethod -Uri $OrgUrl -Method Get -UseDefaultCredential -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)})
$ListProjectCount = $ListProject.count
Write-Host  $ListProjectCount 

$ListProjectName= $ListProject.value.name

ForEach ($Name in $ListProjectName)
{
Write-Host  $Name
}

Result: enter image description here

We also can use client API to list the project, corresponding Code in C#:

using (var client = new HttpClient())
{
    client.BaseAddress = new Uri("{org url}");
    client.DefaultRequestHeaders.Accept.Clear();
    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", {credentials});

    HttpResponseMessage response = client.GetAsync("_apis/projects?$top=250&stateFilter=All&api-version=1.0").Result;


    if (response.IsSuccessStatusCode)
    {
        responseString = response.Content.ReadAsStringAsync().Result.ToString();
    }
    else
    {
        //failed
    }
}

// Convert responseString into a json Object
RootObj jsonObj = JsonConvert.DeserializeObject<RootObj>(responseString);
Console.WriteLine("Found " + jsonObj.Count + " projects");

//Do stuff
foreach (var obj in jsonObj.Value)
{
    //foreach project...
}

Update1

List all repositories:

GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories?api-version=6.0-preview.1

We can get the repo ID, then You can use the API below to list repo files:

GET https://dev.azure.com/{org name}/{project name}/_apis/git/repositories/{repo ID}/items?recursionLevel=Full&api-version=4.1

Result:

enter image description here

Upvotes: 2

Related Questions