Skip to content

Commit

Permalink
Merge pull request #1373 from mdaneri/smart-dll-loader
Browse files Browse the repository at this point in the history
Dynamically load the Pode DLL relevant to the version of PowerShell
  • Loading branch information
Badgerati authored Sep 4, 2024
2 parents 40f9eaa + 056572b commit 78aa711
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
3 changes: 1 addition & 2 deletions pode.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,6 @@ Task TestNoBuild TestDeps, {
# Synopsis: Run tests after a build
Task Test Build, TestNoBuild


# Synopsis: Check if any of the tests failed
Task CheckFailedTests {
if ($TestStatus.FailedCount -gt 0) {
Expand Down Expand Up @@ -987,4 +986,4 @@ task ReleaseNotes {
$categories[$category] | Sort-Object | ForEach-Object { Write-Host $_ }
Write-Host ''
}
}
}
24 changes: 17 additions & 7 deletions src/Pode.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,25 @@ try {
}
}
else {
if ($PSVersionTable.PSVersion -ge [version]'7.4.0') {
Add-Type -LiteralPath "$($root)/Libs/net8.0/Pode.dll" -ErrorAction Stop
# fetch the .net version and the libs path
$version = [System.Environment]::Version.Major
$libsPath = "$($root)/Libs"

# filter .net dll folders based on version above, and get path for latest version found
if (![string]::IsNullOrWhiteSpace($version)) {
$netFolder = Get-ChildItem -Path $libsPath -Directory -Force |
Where-Object { $_.Name -imatch "net[1-$($version)]" } |
Sort-Object -Property Name -Descending |
Select-Object -First 1 -ExpandProperty FullName
}
elseif ($PSVersionTable.PSVersion -ge [version]'7.2.0') {
Add-Type -LiteralPath "$($root)/Libs/net6.0/Pode.dll" -ErrorAction Stop
}
else {
Add-Type -LiteralPath "$($root)/Libs/netstandard2.0/Pode.dll" -ErrorAction Stop

# use netstandard if no folder found
if ([string]::IsNullOrWhiteSpace($netFolder)) {
$netFolder = "$($libsPath)/netstandard2.0"
}

# append Pode.dll and mount
Add-Type -LiteralPath "$($netFolder)/Pode.dll" -ErrorAction Stop
}

# load private functions
Expand Down

0 comments on commit 78aa711

Please sign in to comment.