fix(ci): remove all deps/runtimeconfig json and unset DOTNET_ROOT in-process

Previous approach of env: DOTNET_ROOT='' at the step level wasn't
sufficient — the .NET runtime may have already cached the original
DOTNET_ROOT before pwsh started. Now:

- Remove *.deps.json AND *.runtimeconfig.json from publish output
- Unset DOTNET_ROOT via $env:DOTNET_ROOT = $null inside the pwsh script
- _TestHelper.ps1 also unsets DOTNET_ROOT and cleans deps/runtimeconfig

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Clint Branham
2026-03-19 09:06:24 -05:00
parent afb1693f94
commit 35805959f4
3 changed files with 21 additions and 11 deletions
+2 -2
View File
@@ -180,8 +180,8 @@ jobs:
- name: Build module
run: dotnet publish src/PSProxmoxVE/PSProxmoxVE.csproj --configuration Release --framework net9.0 --output ./publish/net9.0
- name: Remove deps.json from publish output
run: rm -f ./publish/net9.0/PSProxmoxVE.deps.json
- name: Clean publish output for PS module loading
run: rm -f ./publish/net9.0/*.deps.json ./publish/net9.0/*.runtimeconfig.json
- name: Install Pester 5
shell: pwsh
+7 -5
View File
@@ -43,9 +43,9 @@ jobs:
- name: Build module
run: dotnet publish src/PSProxmoxVE/PSProxmoxVE.csproj --configuration Release --framework ${{ matrix.framework }} --output ./publish/${{ matrix.framework }}
- name: Remove deps.json from publish output
- name: Clean publish output for PS module loading
shell: bash
run: rm -f ./publish/${{ matrix.framework }}/PSProxmoxVE.deps.json
run: rm -f ./publish/${{ matrix.framework }}/*.deps.json ./publish/${{ matrix.framework }}/*.runtimeconfig.json
- name: Install Pester 5 (PS 5.1)
if: matrix.ps_version == '5.1'
@@ -111,10 +111,12 @@ jobs:
- name: Run Pester tests (PS 7.x)
if: matrix.ps_version != '5.1'
shell: pwsh
env:
DOTNET_ROOT: ''
DOTNET_MULTILEVEL_LOOKUP: ''
run: |
# Prevent setup-dotnet's DOTNET_ROOT from overriding PS's bundled runtime
[Environment]::SetEnvironmentVariable('DOTNET_ROOT', $null)
[Environment]::SetEnvironmentVariable('DOTNET_MULTILEVEL_LOOKUP', $null)
$env:DOTNET_ROOT = $null
$env:DOTNET_MULTILEVEL_LOOKUP = $null
Import-Module Pester -MinimumVersion 5.0
$config = New-PesterConfiguration
$config.Run.Path = "tests/PSProxmoxVE.Tests"
+12 -4
View File
@@ -8,6 +8,13 @@
# If the module is already loaded, nothing to do.
if (Get-Module -Name PSProxmoxVE) { return }
# Ensure DOTNET_ROOT doesn't override PS's bundled runtime (CI sets this
# via setup-dotnet and it can break binary module assembly resolution).
if ($env:DOTNET_ROOT) {
$env:DOTNET_ROOT = $null
$env:DOTNET_MULTILEVEL_LOOKUP = $null
}
# 1. Try importing by module name (works in CI where the module is
# installed to a PSModulePath location via dotnet publish + copy).
$available = Get-Module PSProxmoxVE -ListAvailable -ErrorAction SilentlyContinue
@@ -43,9 +50,10 @@ if ($null -eq $moduleManifest) {
throw "PSProxmoxVE module not found. Build the project before running Pester tests."
}
# Remove deps.json if present — it causes assembly resolution conflicts
# when loading a binary module inside PowerShell's own .NET runtime.
$depsJson = Join-Path (Split-Path $moduleManifest) 'PSProxmoxVE.deps.json'
if (Test-Path $depsJson) { Remove-Item $depsJson -Force }
# Remove files that cause .NET assembly resolution conflicts when loading
# a binary module inside PowerShell's own runtime.
$moduleDir = Split-Path $moduleManifest
Get-ChildItem $moduleDir -Filter '*.deps.json' -ErrorAction SilentlyContinue | Remove-Item -Force
Get-ChildItem $moduleDir -Filter '*.runtimeconfig.json' -ErrorAction SilentlyContinue | Remove-Item -Force
Import-Module $moduleManifest -Force -ErrorAction Stop