Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
mdaneri committed Sep 2, 2024
1 parent 53c7fe5 commit 056572b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 55 deletions.
43 changes: 3 additions & 40 deletions pode.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -545,45 +545,8 @@ Task TestNoBuild TestDeps, {
}
}, PushCodeCoverage, CheckFailedTests

# Synopsis: Run tests after a build if needed
Task Test {

# Get the .NET framework description to determine the runtime version
$frameworkDescription = [System.Runtime.InteropServices.RuntimeInformation]::FrameworkDescription
$found = $false

# Match and extract the major version number from the framework description
if ($frameworkDescription -match '(\d+)\.(\d+)\.(\d+)') {
$majorVersion = [int]$matches[1]

# Loop through the major versions from the detected version down to 6
for ($version = $majorVersion; $version -ge 6; $version--) {
# Check if the corresponding Pode.dll file exists for the version
if (Test-Path "./src/Libs/net$version.0/Pode.dll") {
$found = $true
break
}
}
}

# If no specific versioned Pode.dll was found, check for the netstandard2.0 version
if (-not $found) {
$found = Test-Path "./src/Libs/netstandard2.0/Pode.dll"
}

# If any Pode.dll was found, skip the build task
if ($found) {
Write-Output 'Build Task not needed'
}
else {
# If no Pode.dll was found, invoke the build task
Invoke-Build Build
}

# Always run the test task, assuming that the build task has already been run if needed
Invoke-Build TestNoBuild
}

# Synopsis: Run tests after a build
Task Test Build, TestNoBuild

# Synopsis: Check if any of the tests failed
Task CheckFailedTests {
Expand Down Expand Up @@ -1023,4 +986,4 @@ task ReleaseNotes {
$categories[$category] | Sort-Object | ForEach-Object { Write-Host $_ }
Write-Host ''
}
}
}
30 changes: 15 additions & 15 deletions src/Pode.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,25 @@ try {
}
}
else {
$frameworkDescription = [System.Runtime.InteropServices.RuntimeInformation]::FrameworkDescription
$loaded = $false
if ($frameworkDescription -match '(\d+)\.(\d+)\.(\d+)') {
$majorVersion = [int]$matches[1]

for ($version = $majorVersion; $version -ge 6; $version--) {
$dllPath = "$($root)/Libs/net$version.0/Pode.dll"
if (Test-Path $dllPath) {
Add-Type -LiteralPath $dllPath -ErrorAction Stop
$loaded = $true
break
}
}
# 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
}

if (-not $loaded) {
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 056572b

Please sign in to comment.