Fix warnings, update version format, organize DLLs in subfolder, and use System.Reflection.Assembly::LoadBytes

This commit is contained in:
GraceSolutions
2025-04-14 22:57:09 -04:00
parent afcb6dbbfa
commit bfbc031a76
15 changed files with 49 additions and 12 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
@{
RootModule = 'PSOPNSenseAPI.dll'
ModuleVersion = '2025.04.14.2246'
RootModule = 'PSOPNSenseAPI.psm1'
ModuleVersion = '2025.04.14.2253'
GUID = '1f0e4b77-cc7c-4a1e-b45a-d7c51a3c562e'
Author = 'PSOPNSenseAPI Contributors'
CompanyName = 'PSOPNSenseAPI'
+25
View File
@@ -0,0 +1,25 @@
# Load assemblies from the lib folder using System.Reflection.Assembly::LoadBytes
# This avoids file lock issues when the module is loaded
$libPath = Join-Path $PSScriptRoot "lib"
$dllFiles = Get-ChildItem -Path $libPath -Filter "*.dll"
foreach ($dll in $dllFiles) {
try {
$dllBytes = [System.IO.File]::ReadAllBytes($dll.FullName)
[System.Reflection.Assembly]::Load($dllBytes) | Out-Null
Write-Verbose "Loaded assembly: $($dll.Name)"
}
catch {
Write-Warning "Failed to load assembly $($dll.Name): $_"
}
}
# Export all cmdlets
$cmdlets = [System.AppDomain]::CurrentDomain.GetAssemblies() |
Where-Object { $_.FullName -like "*PSOPNSenseAPI*" } |
ForEach-Object { $_.GetTypes() } |
Where-Object { $_.IsPublic -and $_.IsClass -and $_.Name -like "*Cmdlet" } |
ForEach-Object { $_.Name }
Export-ModuleMember -Cmdlet $cmdlets