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