src/private/Invoke-ExtractPackageFiles.ps1

function Invoke-ExtractPackageFiles {
    [CmdletBinding()]
    param (
        [string]
        $PackageDir
    )
    
    $packagePath = Join-Path $packageDir "lib"
    $extension = "*.dll"
    
    $frameworks = @( 'net', 'netstandard' )
    
    if ( -not ( Test-Path $packagePath ) ) {
        $packagePath = Join-Path $nugetPackageDir "tools"  
        $extension = "*.exe"
    }

    $FrameworkPath = Get-ChildItem -Path $packagePath | 
        Select-String -Pattern "(net|netstandard)([\d\.]+)" |
        Sort-Object -Property @{ Expression = { $frameworks.IndexOf( $_.Matches[0].Groups[1].Value ) }; Descending = $False }, 
            @{ Expression = { [int] ( ( $_.Matches[0].Groups[2].Value -replace '.' ).PadRight( 10, '0' ) ) }; Descending = $True } | 
        ForEach-Object { $_.ToString() } | 
        Select-Object -First 1
    
    $assemblies = ( Join-Path $packagePath $FrameworkPath ) | Get-ChildItem -Filter $extension -Recurse | ForEach-Object { $_.Name }
    $assemblies
}