52 lines
1.9 KiB
PowerShell
52 lines
1.9 KiB
PowerShell
# Fix projects with UseConcelierTestInfra=false that don't have xunit
|
|
# These projects relied on TestKit for xunit, but now need their own reference
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
$srcPath = "E:\dev\git.stella-ops.org\src"
|
|
|
|
# Find test projects with UseConcelierTestInfra=false
|
|
$projects = Get-ChildItem -Path $srcPath -Recurse -Filter "*.csproj" |
|
|
Where-Object {
|
|
$content = Get-Content $_.FullName -Raw
|
|
($content -match "<UseConcelierTestInfra>\s*false\s*</UseConcelierTestInfra>") -and
|
|
(-not ($content -match "xunit\.v3")) -and # Skip xunit.v3 projects
|
|
(-not ($content -match '<PackageReference\s+Include="xunit"')) # Skip projects that already have xunit
|
|
}
|
|
|
|
Write-Host "Found $($projects.Count) projects needing xunit" -ForegroundColor Cyan
|
|
|
|
$xunitPackages = @'
|
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.0" />
|
|
<PackageReference Include="xunit" Version="2.9.3" />
|
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
|
|
'@
|
|
|
|
$fixedCount = 0
|
|
|
|
foreach ($proj in $projects) {
|
|
$content = Get-Content $proj.FullName -Raw
|
|
|
|
# Check if it has an ItemGroup with PackageReference
|
|
if ($content -match '(<ItemGroup>[\s\S]*?<PackageReference)') {
|
|
# Add xunit packages after first PackageReference ItemGroup opening
|
|
$newContent = $content -replace '(<ItemGroup>\s*\r?\n)(\s*<PackageReference)', "`$1$xunitPackages`n`$2"
|
|
} else {
|
|
# No PackageReference ItemGroup, add one before </Project>
|
|
$itemGroup = @"
|
|
|
|
<ItemGroup>
|
|
$xunitPackages
|
|
</ItemGroup>
|
|
"@
|
|
$newContent = $content -replace '</Project>', "$itemGroup`n</Project>"
|
|
}
|
|
|
|
if ($newContent -ne $content) {
|
|
Set-Content -Path $proj.FullName -Value $newContent -NoNewline
|
|
Write-Host "Fixed: $($proj.Name)" -ForegroundColor Green
|
|
$fixedCount++
|
|
}
|
|
}
|
|
|
|
Write-Host "`nFixed $fixedCount projects" -ForegroundColor Cyan
|