save progress
This commit is contained in:
40
devops/scripts/fix-xunit-using.ps1
Normal file
40
devops/scripts/fix-xunit-using.ps1
Normal file
@@ -0,0 +1,40 @@
|
||||
# Add <Using Include="Xunit" /> to test projects with UseConcelierTestInfra=false
|
||||
# that have xunit but don't have the global using
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$srcPath = "E:\dev\git.stella-ops.org\src"
|
||||
|
||||
# Find test projects with UseConcelierTestInfra=false that have xunit but no Using Include="Xunit"
|
||||
$projects = Get-ChildItem -Path $srcPath -Recurse -Filter "*.csproj" |
|
||||
Where-Object {
|
||||
$content = Get-Content $_.FullName -Raw
|
||||
($content -match "<UseConcelierTestInfra>\s*false\s*</UseConcelierTestInfra>") -and
|
||||
($content -match '<PackageReference\s+Include="xunit"') -and
|
||||
(-not ($content -match '<Using\s+Include="Xunit"'))
|
||||
}
|
||||
|
||||
Write-Host "Found $($projects.Count) projects needing Xunit using" -ForegroundColor Cyan
|
||||
|
||||
$fixedCount = 0
|
||||
|
||||
foreach ($proj in $projects) {
|
||||
$content = Get-Content $proj.FullName -Raw
|
||||
|
||||
# Add Using Include="Xunit" before first ProjectReference ItemGroup or at end
|
||||
if ($content -match '(<ItemGroup>\s*\r?\n\s*<ProjectReference)') {
|
||||
$usingBlock = " <ItemGroup>`n <Using Include=`"Xunit`" />`n </ItemGroup>`n`n"
|
||||
$newContent = $content -replace '(\s*)(<ItemGroup>\s*\r?\n\s*<ProjectReference)', "$usingBlock`$1`$2"
|
||||
} else {
|
||||
# Add before </Project>
|
||||
$usingBlock = "`n <ItemGroup>`n <Using Include=`"Xunit`" />`n </ItemGroup>`n"
|
||||
$newContent = $content -replace '</Project>', "$usingBlock</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
|
||||
Reference in New Issue
Block a user