|
| 1 | +param() |
| 2 | + |
| 3 | +$ErrorActionPreference = 'Stop' |
| 4 | + |
| 5 | +Write-Host "Creating global.json to enforce .NET 8 for MSBuild" |
| 6 | +$globalJson = '{"sdk":{"version":"8.0.0","rollForward":"latestFeature"}}' |
| 7 | +[System.IO.File]::WriteAllText('global.json', $globalJson, [System.Text.Encoding]::UTF8) |
| 8 | + |
| 9 | +Write-Host "Searching for project files under Tests/TestData..." |
| 10 | +$projFiles = Get-ChildItem -Path Tests/TestData -Recurse -Include *.csproj,*.vbproj,*.fsproj -File -ErrorAction SilentlyContinue |
| 11 | + |
| 12 | +if (-not $projFiles) { |
| 13 | + Write-Host "No project files found under Tests/TestData" |
| 14 | + exit 0 |
| 15 | +} |
| 16 | + |
| 17 | +$changed = $false |
| 18 | +foreach ($f in $projFiles) { |
| 19 | + $path = $f.FullName |
| 20 | + Write-Host "Processing: $path" |
| 21 | + |
| 22 | + # Use StreamReader to detect encoding and preserve it when writing back |
| 23 | + $sr = [System.IO.StreamReader]::new($path, $true) |
| 24 | + try { |
| 25 | + $content = $sr.ReadToEnd() |
| 26 | + $encoding = $sr.CurrentEncoding |
| 27 | + } finally { |
| 28 | + $sr.Close() |
| 29 | + } |
| 30 | + |
| 31 | + # Replace net10.0 and net10.0-windows with net8.0 / net8.0-windows |
| 32 | + $updated = [System.Text.RegularExpressions.Regex]::Replace($content, '<TargetFramework>net10\.0(-windows)?</TargetFramework>', '<TargetFramework>net8.0$1</TargetFramework>') |
| 33 | + |
| 34 | + if ($updated -ne $content) { |
| 35 | + Write-Host "Updating TargetFramework in: $path" |
| 36 | + # Write back preserving detected encoding and internal newlines |
| 37 | + [System.IO.File]::WriteAllText($path, $updated, $encoding) |
| 38 | + $changed = $true |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +if ($changed) { |
| 43 | + Write-Host "Changes detected — committing to local repo so working tree is clean for tests" |
| 44 | + git config user.name "github-actions[bot]" |
| 45 | + if ($env:GITHUB_ACTOR) { |
| 46 | + git config user.email "$($env:GITHUB_ACTOR)@users.noreply.github.com" |
| 47 | + } else { |
| 48 | + git config user.email "[email protected]" |
| 49 | + } |
| 50 | + git add -A |
| 51 | + git commit -m "CI: Update Tests/TestData TargetFramework -> net8.0 for .NET 8 run" || Write-Host "No commit created (maybe no staged changes)" |
| 52 | + Write-Host "Committed changes locally." |
| 53 | +} else { |
| 54 | + Write-Host "No TargetFramework updates required." |
| 55 | +} |
| 56 | + |
| 57 | +Write-Host "Done." |
0 commit comments