@@ -57,14 +57,68 @@ jobs:
5757 if : matrix.os == 'windows-latest'
5858 shell : pwsh
5959 run : |
60- # Install .NET Framework 4.8 Developer Pack for building net48 projects
61- $installerUrl = "https://download.visualstudio.microsoft.com/download/pr/014120d7-d689-4305-befd-3cb711108212/0fd66638cde16859462a6243a4629a50/ndp48-devpack-enu.exe"
62- $installerPath = "$env:TEMP\ndp48-devpack-enu.exe"
63- Write-Host "Downloading .NET Framework 4.8 Developer Pack..."
64- Invoke-WebRequest -Uri $installerUrl -OutFile $installerPath
65- Write-Host "Installing .NET Framework 4.8 Developer Pack..."
66- Start-Process -FilePath $installerPath -ArgumentList "/quiet", "/norestart" -Wait
67- Write-Host ".NET Framework 4.8 Developer Pack installed."
60+ # Check registry for .NET Framework 4.8 (Release >= 528040 indicates 4.8)
61+ try { $reg = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full' -ErrorAction Stop; $release = $reg.Release } catch { $release = 0 }
62+
63+ if ($release -ge 528040) {
64+ Write-Host ".NET Framework 4.8 or higher already installed (Release=$release). Skipping install."
65+ exit 0
66+ }
67+
68+ Write-Host "No .NET Framework 4.8 Developer Pack found (Release=$release). Installing..."
69+
70+ # Ensure TLS 1.2 for secure downloads
71+ [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
72+
73+ # Resolve the current Microsoft download link by scraping the official docs page
74+ $downloadPage = 'https://learn.microsoft.com/en-us/dotnet/framework/install/dotnet-48'
75+ Write-Host "Resolving installer URL from: $downloadPage"
76+
77+ try {
78+ $page = (Invoke-WebRequest -Uri $downloadPage -ErrorAction Stop).Content
79+ if ($page -match 'https://download\.visualstudio\.microsoft\.com/[^\s"''<>]+ndp48-devpack-enu\.exe') { $link = $Matches[0] }
80+ } catch {
81+ $link = $null
82+ }
83+
84+ if (-not $link) {
85+ throw "Failed to resolve download URL for ndp48-devpack-enu.exe from Microsoft documentation. Please update the workflow with a valid installer URL."
86+ }
87+
88+ Write-Host "Resolved download URL: $link"
89+
90+ $installerPath = Join-Path $env:TEMP 'ndp48-devpack-enu.exe'
91+
92+ # Download with retries; prefer BITS when available
93+ $maxAttempts = 5
94+ for ($i = 1; $i -le $maxAttempts; $i++) {
95+ try {
96+ if (Get-Command Start-BitsTransfer -ErrorAction SilentlyContinue) {
97+ Start-BitsTransfer -Source $link -Destination $installerPath -ErrorAction Stop
98+ } else {
99+ Invoke-WebRequest -Uri $link -OutFile $installerPath -UseBasicParsing -ErrorAction Stop
100+ }
101+ break
102+ } catch {
103+ Write-Warning "Download attempt $i failed: $($_.Exception.Message)"
104+ if ($i -eq $maxAttempts) { throw "Failed to download .NET Framework 4.8 Developer Pack after $maxAttempts attempts." }
105+ Start-Sleep -Seconds (15 * $i)
106+ }
107+ }
108+
109+ Write-Host "Running installer: $installerPath"
110+ Start-Process -FilePath $installerPath -ArgumentList '/quiet','/norestart' -Wait -ErrorAction Stop
111+
112+ # Verify installation
113+ try { $reg = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full' -ErrorAction Stop; $newRelease = $reg.Release } catch { $newRelease = 0 }
114+ if ($newRelease -ge 528040) {
115+ Write-Host ".NET Framework 4.8 Developer Pack installed (Release=$newRelease)."
116+ } else {
117+ throw ".NET Framework 4.8 installation completed but registry Release value is $newRelease."
118+ }
119+
120+ # Cleanup
121+ if (Test-Path $installerPath) { Remove-Item $installerPath -Force -ErrorAction SilentlyContinue }
68122
69123 - name : Restore, Build, Test
70124 run : dotnet test --framework ${{ matrix.dotnet-tfm }} --configuration ${{ env.buildConfiguration }} --verbosity quiet --logger trx --collect:"XPlat Code Coverage" --results-directory "TestResults-${{ matrix.dotnet-tfm }}"
0 commit comments