Skip to content
This repository was archived by the owner on Apr 12, 2022. It is now read-only.

Commit 6ff7d0d

Browse files
Update
1 parent 4debe43 commit 6ff7d0d

1 file changed

Lines changed: 44 additions & 17 deletions

File tree

PSWriteWord.psm1

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,54 @@
44
#Get public and private function definition files.
55
$Public = @( Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -ErrorAction SilentlyContinue -Recurse )
66
$Private = @( Get-ChildItem -Path $PSScriptRoot\Private\*.ps1 -ErrorAction SilentlyContinue -Recurse )
7-
if ($PSEdition -eq 'Core') {
8-
$Assembly = @( Get-ChildItem -Path $PSScriptRoot\Lib\Core\*.dll -ErrorAction SilentlyContinue )
9-
} else {
10-
$Assembly = @( Get-ChildItem -Path $PSScriptRoot\Lib\Default\*.dll -ErrorAction SilentlyContinue )
11-
}
127

13-
Foreach ($import in @($Assembly)) {
14-
Try {
15-
Add-Type -Path $import.fullname
16-
} Catch {
17-
Write-Error -Message "Failed to import DLL $($import.fullname): $_"
8+
$AssemblyFolders = Get-ChildItem -Path $PSScriptRoot\Lib -Directory -ErrorAction SilentlyContinue
9+
if ($AssemblyFolders.BaseName -contains 'Standard') {
10+
$Assembly = @( Get-ChildItem -Path $PSScriptRoot\Lib\Standard\*.dll -ErrorAction SilentlyContinue )
11+
} else {
12+
if ($PSEdition -eq 'Core') {
13+
$Assembly = @( Get-ChildItem -Path $PSScriptRoot\Lib\Core\*.dll -ErrorAction SilentlyContinue )
14+
} else {
15+
$Assembly = @( Get-ChildItem -Path $PSScriptRoot\Lib\Default\*.dll -ErrorAction SilentlyContinue )
1816
}
1917
}
20-
21-
#Dot source the files
22-
Foreach ($import in @($Public + $Private)) {
23-
Try {
24-
. $import.fullname
25-
} Catch {
26-
Write-Error -Message "Failed to import function $($import.fullname): $_"
18+
$FoundErrors = @(
19+
Foreach ($Import in @($Assembly)) {
20+
try {
21+
Add-Type -Path $Import.Fullname -ErrorAction Stop
22+
} catch [System.Reflection.ReflectionTypeLoadException] {
23+
Write-Warning "Processing $($Import.Name) Exception: $($_.Exception.Message)"
24+
$LoaderExceptions = $($_.Exception.LoaderExceptions) | Sort-Object -Unique
25+
foreach ($E in $LoaderExceptions) {
26+
Write-Warning "Processing $($Import.Name) LoaderExceptions: $($E.Message)"
27+
}
28+
$true
29+
#Write-Error -Message "StackTrace: $($_.Exception.StackTrace)"
30+
} catch {
31+
Write-Warning "Processing $($Import.Name) Exception: $($_.Exception.Message)"
32+
$LoaderExceptions = $($_.Exception.LoaderExceptions) | Sort-Object -Unique
33+
foreach ($E in $LoaderExceptions) {
34+
Write-Warning "Processing $($Import.Name) LoaderExceptions: $($E.Message)"
35+
}
36+
$true
37+
#Write-Error -Message "StackTrace: $($_.Exception.StackTrace)"
38+
}
39+
}
40+
#Dot source the files
41+
Foreach ($Import in @($Private + $Public)) {
42+
Try {
43+
. $Import.Fullname
44+
} Catch {
45+
Write-Error -Message "Failed to import functions from $($import.Fullname): $_"
46+
$true
47+
}
2748
}
49+
)
50+
51+
if ($FoundErrors.Count -gt 0) {
52+
$ModuleName = (Get-ChildItem $PSScriptRoot\*.psd1).BaseName
53+
Write-Warning "Importing module $ModuleName failed. Fix errors before continuing."
54+
break
2855
}
2956

3057
Export-ModuleMember -Function '*' -Alias '*'

0 commit comments

Comments
 (0)