internal/Get-PackagesInRepo.ps1

<#
.SYNOPSIS
Get packages config from vsts or tfs instance
 
.DESCRIPTION
Get packages config from vsts or tfs instance
 
.PARAMETER tfsSiteUrl
the first bit of the url up to the collection
 
.PARAMETER project
The project below the collection
 
.PARAMETER repository
The Repository inside the project
 
.EXAMPLE
Get-PackagesInRepo -tfsSiteUrl http://tfs/tfs/defaultcollection -project project -repository gitrepo
 
.NOTES
General notes
#>

function Get-PackagesInRepo {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory = $true)]
        [String]
        $tfsSiteUrl,
        [Parameter(Mandatory = $true)]
        [String]
        $project,
        [Parameter(Mandatory = $true)]
        [String]
        $repository
    )

    begin {
        $url = "$tfsSiteUrl/$project/_apis/git/repositories/$repository/items"
        $combined = [xml]"<?xml version=""1.0"" encoding=""utf-8""?><packages></packages>"
    }
    process {
        $repo = Get-WebRequest "$($url)?recursionLevel=Full&includeContentMetadata=true&api-version=1.0" | ConvertFrom-json

        Write-Information "Start combine package lists"

        $packages = $repo.value | Where-Object { $_.path -like "*/packages.config" }

        foreach ($package in $packages) {
           $xml = Get-PackageConfigFromRepo -url $url -packageObject $package

            foreach ($child in $xml.packages.ChildNodes) {        
                $childcheck = $combined.packages.ChildNodes
                if (($childcheck | Where-Object { $_.id -eq $child.id -and $_.version -eq $child.version -and $_.targetFramework -eq $child.targetFramework }) -ne $null) {
                    Write-Debug "got one: $($child.id):$($child.version):$($child.targetFramework)"
                    continue
                }
                $ch = $combined.CreateElement("package")

                $ch.SetAttribute("id", $child.id)
                $ch.SetAttribute("version", $child.version)
                $ch.SetAttribute("targetFramework", $child.targetFramework)
        
                Write-Debug $combined.DocumentElement.AppendChild($ch)        
            }
        }

        Write-Information "End combine package lists"
    }
    end {
        $combined
    }
}