From 35805959f401314369578be6cbcc29034ceb568e Mon Sep 17 00:00:00 2001 From: Clint Branham Date: Thu, 19 Mar 2026 09:06:24 -0500 Subject: [PATCH] fix(ci): remove all deps/runtimeconfig json and unset DOTNET_ROOT in-process MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- .github/workflows/integration-tests.yml | 4 ++-- .github/workflows/unit-tests.yml | 12 +++++++----- tests/PSProxmoxVE.Tests/_TestHelper.ps1 | 16 ++++++++++++---- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index c9917c3..4096c16 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -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 diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 3f91a56..914a7f2 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -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" diff --git a/tests/PSProxmoxVE.Tests/_TestHelper.ps1 b/tests/PSProxmoxVE.Tests/_TestHelper.ps1 index a249604..57cc926 100644 --- a/tests/PSProxmoxVE.Tests/_TestHelper.ps1 +++ b/tests/PSProxmoxVE.Tests/_TestHelper.ps1 @@ -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