functions/helpers/Add-PackageTypes.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
function Add-PackageTypes { param( [Parameter(Mandatory = $true)] [string]$LibsDirectory ) process { $exceptions = @() foreach ($path in (Get-ChildItem $LibsDirectory | Where-Object { $_.Name -like '*.dll' } | Select-Object -ExpandProperty FullName)) { try { Add-Type -Path $path } catch [System.Reflection.ReflectionTypeLoadException] { $ex = $_.Exception Write-Host $ex.Message -ForegroundColor Yellow Write-Host $ex.StackTrace -ForegroundColor DarkYellow if($null -ne $ex.LoaderExceptions) { foreach($loaderEx in $ex.LoaderExceptions) { Write-Host "LoaderException: $loaderEx" -ForegroundColor Cyan } } $exceptions += $ex } } if($exceptions.Length -gt 0){ throw (New-Object -TypeName System.AggregateException -ArgumentList $exceptions) } } } |