# Remove duplicate test package references from .Tests.csproj files # These are already centrally defined in src/Directory.Build.props # This script handles both self-closing # and extended elements with child nodes like and param( [string]$SrcPath = "E:\dev\git.stella-ops.org\src", [switch]$DryRun ) $packagesToRemove = @( 'xunit', 'xunit.runner.visualstudio', 'Microsoft.NET.Test.Sdk', 'coverlet.collector', 'Microsoft.AspNetCore.Mvc.Testing', 'Microsoft.Extensions.TimeProvider.Testing' ) $testProjects = Get-ChildItem -Path $SrcPath -Filter "*.Tests.csproj" -Recurse $modifiedCount = 0 $modifiedFiles = @() foreach ($proj in $testProjects) { $content = Get-Content $proj.FullName -Raw $modified = $false foreach ($pkg in $packagesToRemove) { # Pattern 1: Self-closing $pattern1 = '\s*\s*' if ($content -match $pattern1) { $content = $content -replace $pattern1, "`n" $modified = $true } # Pattern 2: Extended elements with child nodes # ... $pattern2 = '\s*]*>[\s\S]*?\s*' if ($content -match $pattern2) { $content = $content -replace $pattern2, "`n" $modified = $true } } if ($modified) { # Clean up multiple blank lines $content = $content -replace '(\r?\n){3,}', "`r`n`r`n" if (-not $DryRun) { Set-Content $proj.FullName -Value $content.TrimEnd() -NoNewline } $modifiedCount++ $modifiedFiles += $proj.Name Write-Host "Modified: $($proj.Name)" } } Write-Host "`n=== Summary ===" Write-Host "Total test projects scanned: $($testProjects.Count)" Write-Host "Total modified: $modifiedCount" if ($DryRun) { Write-Host "(DRY RUN - no files were changed)" }