Skip to content

fix(ci): pin PSDepend to 0.4.1 to fix PowerShell 5.1 bootstrap#471

Merged
HeyItsGilbert merged 1 commit into
mainfrom
fix/psdepend-pin-0.4.1-ps51
Jun 19, 2026
Merged

fix(ci): pin PSDepend to 0.4.1 to fix PowerShell 5.1 bootstrap#471
HeyItsGilbert merged 1 commit into
mainfrom
fix/psdepend-pin-0.4.1-ps51

Conversation

@HeyItsGilbert

Copy link
Copy Markdown
Member

Summary

The Run Tests (PowerShell 5.1) CI job has been failing on every PR (e.g. #468, #469, #470) during build.ps1 -Bootstrap with:

PSDepend\0.3.8\Private\SemanticVersion.ps1: Cannot add type.
The type name 'System.Management.Automation.SemanticVersion' already exists.

Root cause

PSDepend 0.3.8 ships an unguarded Add-Type for its Windows PowerShell 5.1 SemanticVersion polyfill:

if ($PSVersionTable.PSVersion.Major -lt 6) {
  Add-Type -TypeDefinition $code
}

On PS 5.1, System.Management.Automation.SemanticVersion is not a built-in type, so this runs. When PSDepend is imported a second time in the same session — which the bootstrap triggers because PSDepend is pinned as a dependency of itself in requirements.psd1 — the Add-Type throws, since the type already exists in the AppDomain. PowerShell 6+ is unaffected: the type is built in, so the guard short-circuits.

PSDepend 0.4.1 (newly released) adds the missing existence guard, making the polyfill idempotent:

if ($PSVersionTable.PSVersion.Major -lt 6 -and -not ('System.Management.Automation.SemanticVersion' -as [type])) {
  Add-Type -TypeDefinition $code
}

Fix

Bump the PSDepend pin in requirements.psd1 from 0.3.80.4.1.

Reproduction / verification

Reproduced on local Windows PowerShell 5.1 (5.1.26100) by pre-defining the type then dot-sourcing each version's SemanticVersion.ps1:

PSDepend Result
0.3.8 Cannot add type. The type name 'System.Management.Automation.SemanticVersion' already exists.
0.4.1 ✅ no-op (guard skips Add-Type)

CI will confirm the PS 5.1 job goes green on this PR.

🤖 Generated with Claude Code

build.ps1 -Bootstrap failed on Windows PowerShell 5.1 with:

  PSDepend\0.3.8\Private\SemanticVersion.ps1: Cannot add type.
  The type name 'System.Management.Automation.SemanticVersion'
  already exists.

PSDepend 0.3.8 ships an unguarded Add-Type for its PS5.1
SemanticVersion polyfill (`if ($PSVersionTable.PSVersion.Major -lt 6)`).
On PS5.1 the type isn't built in, so when PSDepend is imported a second
time in the same session — as happens during bootstrap when PSDepend is
listed as a dependency of itself — the second Add-Type throws because
the type already exists. PS6+ is unaffected since the type is built in
and the guard short-circuits.

PSDepend 0.4.1 adds the missing existence guard
(`-and -not ('System.Management.Automation.SemanticVersion' -as [type])`),
making the polyfill idempotent. Bump the pin to 0.4.1.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@HeyItsGilbert HeyItsGilbert merged commit ff47c2d into main Jun 19, 2026
5 of 6 checks passed
@HeyItsGilbert HeyItsGilbert deleted the fix/psdepend-pin-0.4.1-ps51 branch June 19, 2026 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant