66 lines
2.1 KiB
PowerShell
66 lines
2.1 KiB
PowerShell
# 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 <PackageReference ... />
|
|
# and extended elements with child nodes like <PrivateAssets> and <IncludeAssets>
|
|
|
|
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 <PackageReference Include="pkg" Version="..." />
|
|
$pattern1 = '\s*<PackageReference\s+Include="' + [regex]::Escape($pkg) + '"\s+Version="[^"]*"\s*/>\s*'
|
|
if ($content -match $pattern1) {
|
|
$content = $content -replace $pattern1, "`n"
|
|
$modified = $true
|
|
}
|
|
|
|
# Pattern 2: Extended elements with child nodes
|
|
# <PackageReference Include="pkg" Version="...">...</PackageReference>
|
|
$pattern2 = '\s*<PackageReference\s+Include="' + [regex]::Escape($pkg) + '"[^>]*>[\s\S]*?</PackageReference>\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)"
|
|
}
|