# ============================================================================== # ClassNotify Windows Installer - Standard Production Build Pipeline # Engine: Native Inno Setup 7 + Solid LZMA2 (Slimmed-Down Baseline ~72.7 MB) # ============================================================================== param ( [switch]$SkipPublish = $false ) $ErrorActionPreference = "Stop" $root = $PSScriptRoot if (-not $root) { $root = Get-Location } $dotnet = "C:\Program Files\dotnet\dotnet.exe" $iscc = "C:\Users\Administrator\AppData\Local\Programs\Inno Setup 7\ISCC.exe" $distDir = Join-Path $root "dist" $packagingDir = Join-Path $root "packaging_p2" $stagingDir = Join-Path $packagingDir "staging" $serviceStaging = Join-Path $stagingDir "Service" $clientStaging = Join-Path $stagingDir "Client" $issPath = Join-Path $packagingDir "ClassNotifySetup_p2.iss" $outputDir = Join-Path $packagingDir "output" Write-Host "==========================================================" -ForegroundColor Cyan Write-Host " ClassNotify Production Installer Pipeline (Inno Setup 7)" -ForegroundColor Cyan Write-Host "==========================================================" -ForegroundColor Cyan if (-not (Test-Path $iscc)) { throw "Inno Setup compiler not found at: $iscc" } if (-not $SkipPublish) { Write-Host "`n[1/4] Publishing Windows Service (win-x64, self-contained)..." -ForegroundColor Yellow if (Test-Path $serviceStaging) { Remove-Item $serviceStaging -Recurse -Force } New-Item -ItemType Directory -Path $serviceStaging -Force | Out-Null $serviceProj = Join-Path $root "src\Windows\ClassNotify.Service\ClassNotify.Service.csproj" & $dotnet publish $serviceProj -c Release -r win-x64 --self-contained true -o $serviceStaging if ($LASTEXITCODE -ne 0) { throw "ClassNotify.Service publish failed" } Write-Host "`n[2/4] Publishing WPF Client (win-x64, self-contained)..." -ForegroundColor Yellow if (Test-Path $clientStaging) { Remove-Item $clientStaging -Recurse -Force } New-Item -ItemType Directory -Path $clientStaging -Force | Out-Null $clientProj = Join-Path $root "src\Windows\ClassNotify.Client\ClassNotify.Client.csproj" & $dotnet publish $clientProj -c Release -r win-x64 --self-contained true -o $clientStaging if ($LASTEXITCODE -ne 0) { throw "ClassNotify.Client publish failed" } } # 3. Strip non-production artifacts and sign internal PEs Write-Host "`n[3/5] Sanitizing staging payload (stripping PDBs and signing internal PEs)..." -ForegroundColor Yellow Get-ChildItem -Path $stagingDir -Filter "*.pdb" -Recurse -ErrorAction SilentlyContinue | Remove-Item -Force if (Test-Path (Join-Path $clientStaging "win-x64")) { Remove-Item (Join-Path $clientStaging "win-x64") -Recurse -Force } # Locate or create Code Signing Certificate for Publisher $cert = Get-ChildItem -Path "Cert:\LocalMachine\My" | Where-Object { $_.Subject -like "*CN=ClassNotify*" } | Select-Object -First 1 if (-not $cert) { Write-Host "Creating new ClassNotify Code Signing Certificate..." -ForegroundColor Cyan $cert = New-SelfSignedCertificate -Type CodeSigningCert ` -Subject "CN=ClassNotify 智慧班级大屏系统, O=ClassNotify Team, C=CN" ` -CertStoreLocation "Cert:\LocalMachine\My" ` -HashAlgorithm SHA256 ` -NotAfter (Get-Date).AddYears(5) $rootStore = Get-Item "Cert:\LocalMachine\Root" $rootStore.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite) $rootStore.Add($cert) $rootStore.Close() } function Sign-FileSafe ($filePath, $cert) { if (Test-Path $filePath) { try { Set-AuthenticodeSignature -FilePath $filePath -Certificate $cert -HashAlgorithm SHA256 -TimestampServer "http://timestamp.digicert.com" -ErrorAction Stop | Out-Null } catch { Set-AuthenticodeSignature -FilePath $filePath -Certificate $cert -HashAlgorithm SHA256 | Out-Null } } } # Sign internal executable binaries before packing into installer $svcExe = Join-Path $serviceStaging "ClassNotify.Service.exe" $cliExe = Join-Path $clientStaging "ClassNotify.Client.exe" Sign-FileSafe $svcExe $cert Sign-FileSafe $cliExe $cert Write-Host "Internal PEs signed: ClassNotify.Service.exe & ClassNotify.Client.exe" -ForegroundColor Green # 4. Compile with Inno Setup 7 (LZMA2/max solid compression) Write-Host "`n[4/5] Compiling ClassNotifySetup.exe via Inno Setup 7 (Solid LZMA2)..." -ForegroundColor Yellow if (Test-Path $outputDir) { Remove-Item $outputDir -Recurse -Force } New-Item -ItemType Directory -Path $outputDir -Force | Out-Null if (-not (Test-Path $distDir)) { New-Item -ItemType Directory -Path $distDir -Force | Out-Null } $sw = [System.Diagnostics.Stopwatch]::StartNew() & $iscc "/O$outputDir" $issPath if ($LASTEXITCODE -ne 0) { throw "ISCC compilation failed with exit code $LASTEXITCODE" } $sw.Stop() $builtExe = Join-Path $outputDir "ClassNotifySetup.exe" $distExe = Join-Path $distDir "ClassNotifySetup.exe" $desktopExe = "C:\Users\Administrator\Desktop\ClassNotifySetup.exe" Copy-Item $builtExe $distExe -Force Copy-Item $builtExe $desktopExe -Force # 5. Sign installer with Authenticode Digital Signature to eliminate "Unknown Publisher" Write-Host "`n[5/5] Signing ClassNotifySetup.exe with Authenticode Digital Certificate..." -ForegroundColor Yellow Sign-FileSafe $builtExe $cert Sign-FileSafe $distExe $cert Sign-FileSafe $desktopExe $cert # Verify signature $sig = Get-AuthenticodeSignature -FilePath $distExe if ($sig.Status -ne "Valid") { throw "AUTHENTICODE_VERIFY_FAILED: Signature status on $distExe is $($sig.Status)" } $fileInfo = Get-Item $distExe $finalSizeMb = [math]::Round($fileInfo.Length / 1MB, 2) $hash = (Get-FileHash -Path $distExe -Algorithm SHA256).Hash # Generate SHA256 manifest $manifestPath = "$distExe.sha256" "$hash ClassNotifySetup.exe" | Out-File -FilePath $manifestPath -Encoding UTF8 -Force Copy-Item $manifestPath "C:\Users\Administrator\Desktop\ClassNotifySetup.exe.sha256" -Force # Package-size regression gate (enforce <= 100 MB) if ($finalSizeMb -gt 100) { throw "PACKAGE_SIZE_REGRESSION: Installer size $finalSizeMb MB exceeded 100 MB limit!" } Write-Host "`n==========================================================" -ForegroundColor Green Write-Host " ClassNotifySetup.exe Built, Signed & Packaged Successfully!" -ForegroundColor Green Write-Host " Path: $($fileInfo.FullName)" -ForegroundColor Green Write-Host " Desktop: $desktopExe" -ForegroundColor Green Write-Host " Size: $finalSizeMb MB ($($fileInfo.Length) bytes)" -ForegroundColor Green Write-Host " SHA256: $hash" -ForegroundColor Green Write-Host " Build Time: $([math]::Round($sw.Elapsed.TotalSeconds, 1))s" -ForegroundColor Green Write-Host " Signature: $($sig.Status) ($($sig.SignerCertificate.Subject))" -ForegroundColor Green Write-Host " Gate: All Package Size & Authenticode Gates Passed" -ForegroundColor Green Write-Host "==========================================================" -ForegroundColor Green