Skip to content

Commit 7cf9efe

Browse files
Fix critical bugs and add comprehensive AvoidConflicts support
- Fix undefined variable error on Desktop edition (line 122) - Add Desktop edition support for -AvoidConflicts parameter - Enhance verbose logging for skipped assemblies - Add integration tests to build.yml workflow - Remove standalone test file in favor of workflow tests Co-authored-by: Chrissy LeMaire <potatoqualitee@users.noreply.github.com>
1 parent c7f1e62 commit 7cf9efe

File tree

2 files changed

+20
-123
lines changed

2 files changed

+20
-123
lines changed

dbatools.library.psm1

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ if (-not $skipSqlClient) {
119119
}
120120
}
121121

122-
if ($PSVersionTable.PSEdition -ne "Core") {
122+
if ($PSVersionTable.PSEdition -ne "Core" -and $redirector) {
123123
[System.AppDomain]::CurrentDomain.remove_AssemblyResolve($redirector.EventHandler)
124124
}
125125

@@ -192,15 +192,25 @@ foreach ($name in $names) {
192192
continue
193193
}
194194

195-
$assemblyPath = [IO.Path]::Combine($script:libraryroot, "lib", "$name.dll")
196-
$assemblyfullname = $assemblies.FullName | Out-String
197-
if (-not ($assemblyfullname.Contains("$name,"))) {
198-
$null = try {
199-
$null = Import-Module $assemblyPath
200-
} catch {
201-
Write-Error "Could not import $assemblyPath : $($_ | Out-String)"
195+
# Check if assembly is already loaded when AvoidConflicts is enabled
196+
$skipAssembly = $false
197+
if ($AvoidConflicts) {
198+
$assemblyfullname = $assemblies.FullName | Out-String
199+
if ($assemblyfullname.Contains("$name,")) {
200+
$skipAssembly = $true
201+
Write-Verbose "Skipping $name.dll - already loaded"
202+
}
203+
}
204+
205+
if (-not $skipAssembly) {
206+
$assemblyPath = [IO.Path]::Combine($script:libraryroot, "lib", "$name.dll")
207+
$assemblyfullname = $assemblies.FullName | Out-String
208+
if (-not ($assemblyfullname.Contains("$name,"))) {
209+
$null = try {
210+
$null = Import-Module $assemblyPath
211+
} catch {
212+
Write-Error "Could not import $assemblyPath : $($_ | Out-String)"
213+
}
202214
}
203-
} elseif ($AvoidConflicts) {
204-
Write-Verbose "Skipping $name.dll - already loaded"
205215
}
206216
}

tests/test-avoidconflicts.ps1

Lines changed: 0 additions & 113 deletions
This file was deleted.

0 commit comments

Comments
 (0)