Script compilazioniok!
This commit is contained in:
+1
-1
@@ -1,5 +1,5 @@
|
||||
# Cerca ricorsivamente solo le soluzioni che iniziano con 'IOB-WIN-'
|
||||
$pattern = "IOB-WIN-NEXT.sln"
|
||||
$pattern = "IOB-WIN-*.sln"
|
||||
$solutions = Get-ChildItem -Path . -Filter $pattern -Recurse
|
||||
|
||||
if ($solutions.Count -eq 0) {
|
||||
|
||||
+84
-44
@@ -1,94 +1,134 @@
|
||||
# --- CONFIGURAZIONE ---
|
||||
$pattern = "IOB-WIN-*.sln"
|
||||
# Sostituisci questo percorso con il file .csproj del tuo progetto comune condiviso!
|
||||
$sharedProjectPath = ".\IOB-WIN-FORM\IOB-WIN-FORM.csproj"
|
||||
|
||||
# Cerca tutte le soluzioni
|
||||
$solutions = Get-ChildItem -Path . -Filter $pattern -Recurse
|
||||
# Avvia il cronometro per calcolare il tempo totale
|
||||
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
|
||||
|
||||
# 1. Trova l'MSBuild ufficiale di Visual Studio 2022 (Gestione installazioni multiple corretta)
|
||||
$vsPaths = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -version "[17.0,18.0)" -products * -requires Microsoft.Component.MSBuild -property installationPath
|
||||
if (-not $vsPaths) {
|
||||
Write-Host "❌ Impossibile trovare Visual Studio 2022!" -ForegroundColor Red
|
||||
Exit
|
||||
}
|
||||
$msbuildPath = Join-Path $vsPaths[0] "MSBuild\Current\Bin\MSBuild.exe"
|
||||
Write-Host "🎯 Usando MSBuild di VS2022: $msbuildPath" -ForegroundColor Gray
|
||||
|
||||
# Cerca tutte le soluzioni escludendo cartelle di build
|
||||
$solutions = Get-ChildItem -Path . -Filter $pattern -Recurse | Where-Object {
|
||||
$_.FullName -notmatch '\\(bin|obj|\\.git|\\.vs)\\.'
|
||||
}
|
||||
|
||||
if ($solutions.Count -eq 0) {
|
||||
Write-Host "⚠️ Nessuna soluzione trovata che corrisponde al pattern: $pattern" -ForegroundColor Yellow
|
||||
Exit
|
||||
}
|
||||
|
||||
Write-Host "🚀 Trovate $($solutions.Count) soluzioni." -ForegroundColor Magenta
|
||||
Write-Host "🚀 Trovate $($solutions.Count) soluzioni univoche." -ForegroundColor Magenta
|
||||
|
||||
# FASE 1: Compilazione preventiva del progetto comune
|
||||
# FASE 1: Compilazione preventiva del progetto comune (Usando MSBuild)
|
||||
if (Test-Path $sharedProjectPath) {
|
||||
Write-Host "`n📦 Fase 1: Compilazione del progetto comune condiviso..." -ForegroundColor Cyan
|
||||
dotnet build $sharedProjectPath --configuration Debug
|
||||
& $msbuildPath $sharedProjectPath /p:Configuration=Debug /v:m
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host "❌ Errore critico: Impossibile compilare il progetto comune. Interruzione." -ForegroundColor Red
|
||||
Exit
|
||||
}
|
||||
Write-Host "✅ Progetto comune pronto." -ForegroundColor Green
|
||||
}
|
||||
else {
|
||||
Write-Host "⚠️ Attenzione: Percorso del progetto comune non trovato nello script ($sharedProjectPath)." -ForegroundColor Yellow
|
||||
Write-Host "Il parallelismo potrebbe causare conflitti di file." -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
# FASE 2: Compilazione parallela delle soluzioni senza toccare le dipendenze esterne
|
||||
# FASE 2: Compilazione parallela iniziale
|
||||
Write-Host "`n🛠️ Fase 2: Avvio compilazione parallela delle soluzioni (Max 4)..." -ForegroundColor Magenta
|
||||
Write-Host "==================================================" -ForegroundColor Magenta
|
||||
|
||||
$results = $solutions | ForEach-Object -Parallel {
|
||||
$parallelResults = $solutions | ForEach-Object -Parallel {
|
||||
$solName = $_.Name
|
||||
$solPath = $_.FullName
|
||||
$sharedExists = $using:sharedProjectPath
|
||||
$msb = $using:msbuildPath
|
||||
|
||||
# Se abbiamo compilato prima il progetto comune, usiamo --no-dependencies per evitare lock sui file
|
||||
if ($sharedExists) {
|
||||
$log = dotnet build $solPath --configuration Debug --no-dependencies 2>&1
|
||||
}
|
||||
else {
|
||||
$log = dotnet build $solPath --configuration Debug 2>&1
|
||||
}
|
||||
# Esegue MSBuild nativo catturando i log
|
||||
$log = & $msb $solPath /p:Configuration=Debug /m:1 /p:BuildInParallel=false /v:m 2>&1
|
||||
|
||||
[PSCustomObject]@{
|
||||
Name = $solName
|
||||
Success = ($LASTEXITCODE -eq 0)
|
||||
Log = $log
|
||||
Name = $solName
|
||||
FullName = $solPath
|
||||
Success = ($LASTEXITCODE -eq 0)
|
||||
Log = $log
|
||||
}
|
||||
} -ThrottleLimit 4
|
||||
|
||||
# --- ELABORAZIONE DEI RISULTATI ---
|
||||
$successCount = 0
|
||||
$failCount = 0
|
||||
$failedSolutions = @()
|
||||
# --- ANALISI PRIMO ROUND E FASE 3 (RETRY SEQUENZIALE) ---
|
||||
$successSolutions = @()
|
||||
$failedToRetry = @()
|
||||
|
||||
foreach ($res in $results) {
|
||||
foreach ($res in $parallelResults) {
|
||||
if ($res.Success) {
|
||||
Write-Host "✅ $($res.Name) compilata con successo!" -ForegroundColor Green
|
||||
$successCount++
|
||||
Write-Host "✅ $($res.Name) compilata con successo (in parallelo)!" -ForegroundColor Green
|
||||
$successSolutions += $res.Name
|
||||
}
|
||||
else {
|
||||
Write-Host "❌ Errore nella compilazione di $($res.Name)" -ForegroundColor Red
|
||||
$failCount++
|
||||
$failedSolutions += $res.Name
|
||||
|
||||
Write-Host "--- Dettagli Errore per $($res.Name) ---" -ForegroundColor DarkRed
|
||||
$res.Log | Select-Object -Last 10 | Write-Host -ForegroundColor Gray
|
||||
Write-Host "---------------------------------------" -ForegroundColor DarkRed
|
||||
Write-Host "⚠️ $($res.Name) fallita in parallelo. Accodata per il recupero sequenziale..." -ForegroundColor Yellow
|
||||
$failedToRetry += $res
|
||||
}
|
||||
}
|
||||
|
||||
# Se ci sono falliti, li rieseguiamo UNO ALLA VOLTA pulendo la cache
|
||||
if ($failedToRetry.Count -gt 0) {
|
||||
Write-Host "`n🔄 Fase 3: Riesecuzione sequenziale dei task falliti ($($failedToRetry.Count) soluzioni)..." -ForegroundColor Magenta
|
||||
Write-Host "==================================================" -ForegroundColor Magenta
|
||||
|
||||
foreach ($failedRes in $failedToRetry) {
|
||||
Write-Host "⏳ Ripristino e compilazione sequenziale: $($failedRes.Name)..." -ForegroundColor Cyan
|
||||
|
||||
# 1. Forza un Restore pulito delle dipendenze per questa soluzione
|
||||
& $msbuildPath $failedRes.FullName /t:Restore /v:m > $null
|
||||
# 2. Pulisce eventuali residui corrotti
|
||||
& $msbuildPath $failedRes.FullName /t:Clean /v:m /p:Configuration=Debug > $null
|
||||
# 3. Riprova la Build reale
|
||||
$retryLog = & $msbuildPath $failedRes.FullName /t:Build /p:Configuration=Debug /v:m 2>&1
|
||||
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
Write-Host "✅ FALSO ALLARME: $($failedRes.Name) compilata correttamente in sequenziale!" -ForegroundColor Green
|
||||
$successSolutions += $failedRes.Name
|
||||
}
|
||||
else {
|
||||
Write-Host "❌ ERRORE REALE: $($failedRes.Name) è fallita anche in sequenziale." -ForegroundColor Red
|
||||
# Sovrascriviamo l'oggetto inserendo il log del fallimento sequenziale (più pulito)
|
||||
$failedRes.Log = $retryLog
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Ferma il cronometro e calcola il tempo trascorso
|
||||
$stopwatch.Stop()
|
||||
$elapsedTime = "{0:mm\:ss}" -f $stopwatch.Elapsed
|
||||
|
||||
# --- ELABORAZIONE DEI RISULTATI FINALI ---
|
||||
$totalCount = $solutions.Count
|
||||
$successCount = $successSolutions.Count
|
||||
$failCount = $totalCount - $successCount
|
||||
$failColor = if ($failCount -gt 0) { "Red" } else { "Gray" }
|
||||
|
||||
# --- RIEPILOGO FINALE ---
|
||||
Write-Host "`n==================================================" -ForegroundColor Magenta
|
||||
Write-Host "🏁 Processo di verifica completato!" -ForegroundColor Magenta
|
||||
Write-Host "🏁 Processo di verifica completato in $elapsedTime!" -ForegroundColor Magenta
|
||||
Write-Host "==================================================" -ForegroundColor Magenta
|
||||
Write-Host " Successi: $successCount" -ForegroundColor Green
|
||||
Write-Host " Falliti: $failCount" -ForegroundColor $failColor
|
||||
Write-Host " Soluzioni Totali: $totalCount" -ForegroundColor White
|
||||
Write-Host " Successi totali: $successCount" -ForegroundColor Green
|
||||
Write-Host " Errori reali: $failCount" -ForegroundColor $failColor
|
||||
Write-Host " Tempo impiegato: $elapsedTime" -ForegroundColor Cyan
|
||||
|
||||
if ($failCount -gt 0) {
|
||||
Write-Host "`n❌ Elenco delle soluzioni fallite:" -ForegroundColor Red
|
||||
foreach ($failed in $failedSolutions) {
|
||||
Write-Host " - $failed" -ForegroundColor Red
|
||||
Write-Host "`n❌ Elenco delle soluzioni con ERRORI REALI:" -ForegroundColor Red
|
||||
foreach ($res in $parallelResults) {
|
||||
if ($successSolutions -notcontains $res.Name) {
|
||||
Write-Host " - $($res.Name)" -ForegroundColor Red
|
||||
Write-Host " 👉 Ultimi dettagli errore:" -ForegroundColor DarkRed
|
||||
$res.Log | Where-Object { $_ -match "error" } | Select-Object -First 3 | Write-Host -ForegroundColor Gray
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-Host "`n🎉 Ottimo! Tutte le soluzioni sono state verificate con successo." -ForegroundColor Green
|
||||
Write-Host "`n🎉 Eccellente! Tutte le soluzioni compilano senza errori (i problemi di lock parallelo sono stati superati)." -ForegroundColor Green
|
||||
}
|
||||
Write-Host "==================================================" -ForegroundColor Magenta
|
||||
@@ -0,0 +1,56 @@
|
||||
# --- CONFIGURAZIONE DI TEST ---
|
||||
# Inserisci qui il percorso esatto del file .sln che vuoi testare
|
||||
$solutionPath = "IOB-WIN-NEXT.sln"
|
||||
# $solutionPath = "IOB-WIN-MITSUBISHI.sln"
|
||||
|
||||
|
||||
# --- TROVA MSBUILD (Versione Corretta per installazioni multiple) ---
|
||||
$vsPaths = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -version "[17.0,18.0)" -products * -requires Microsoft.Component.MSBuild -property installationPath
|
||||
|
||||
if (-not $vsPaths) {
|
||||
Write-Host "❌ Impossibile trovare Visual Studio 2022!" -ForegroundColor Red
|
||||
Exit
|
||||
}
|
||||
|
||||
# Prendiamo SOLO LA PRIMA installazione trovata per evitare stringhe doppie
|
||||
$firstVsPath = $vsPaths[0]
|
||||
$msbuildPath = Join-Path $firstVsPath "MSBuild\Current\Bin\MSBuild.exe"
|
||||
|
||||
if (-not (Test-Path $solutionPath)) {
|
||||
Write-Host "❌ Il file della soluzione specificato non esiste: $solutionPath" -ForegroundColor Red
|
||||
Exit
|
||||
}
|
||||
|
||||
Write-Host "🎯 Soluzione sotto test: $solutionPath" -ForegroundColor Cyan
|
||||
Write-Host "🎯 Usando MSBuild: $msbuildPath" -ForegroundColor Gray
|
||||
Write-Host "--------------------------------------------------" -ForegroundColor Gray
|
||||
|
||||
# 1. NuGet Restore
|
||||
Write-Host "📦 [1/3] Ripristino pacchetti NuGet in corso..." -ForegroundColor Yellow
|
||||
& $msbuildPath $solutionPath /t:Restore /v:m
|
||||
if ($LASTEXITCODE -ne 0) { Write-Host "❌ Fallito il ripristino NuGet!" -ForegroundColor Red; Exit }
|
||||
|
||||
# 2. Clean
|
||||
Write-Host "🧹 [2/3] Pulizia soluzione (Clean)..." -ForegroundColor Yellow
|
||||
& $msbuildPath $solutionPath /t:Clean /v:m /p:Configuration=Debug
|
||||
|
||||
# 3. Build reale
|
||||
Write-Host "🚀 [3/3] Compilazione (Build)..." -ForegroundColor Yellow
|
||||
Write-Host "==================================================" -ForegroundColor DarkGray
|
||||
|
||||
# Eseguiamo catturando l'output
|
||||
& $msbuildPath $solutionPath /t:Build /p:Configuration=Debug /v:normal
|
||||
|
||||
# Controllo finale REALE sul codice di uscita dell'ultimo comando eseguito
|
||||
$finalResult = $LASTEXITCODE
|
||||
|
||||
if ($finalResult -eq 0) {
|
||||
Write-Host "`n==================================================" -ForegroundColor Green
|
||||
Write-Host "✅ COMPILAZIONE AVVENUTA CON SUCCESSO!" -ForegroundColor Green
|
||||
Write-Host "==================================================" -ForegroundColor Green
|
||||
}
|
||||
else {
|
||||
Write-Host "`n==================================================" -ForegroundColor Red
|
||||
Write-Host "❌ COMPILAZIONE FALLITA!" -ForegroundColor Red
|
||||
Write-Host "==================================================" -ForegroundColor Red
|
||||
}
|
||||
Reference in New Issue
Block a user