@@ -525,6 +525,39 @@ try {
525525 Write-Host " Output: Output\$Configuration " - ForegroundColor Cyan
526526 }
527527
528+ # =============================================================================
529+ # Test Execution (Optional)
530+ # =============================================================================
531+ # Run tests BEFORE the installer build because the installer's CleanAll target
532+ # (enabled on CI via InstallerCleanProductOutputs=true) wipes Output/ and
533+ # rebuilds without /p:BuildTests=true, removing all *Tests.dll assemblies.
534+
535+ if ($RunTests ) {
536+ Write-Host " "
537+ Write-Host " Running tests..." - ForegroundColor Cyan
538+
539+ $testArgs = @ {
540+ Configuration = $Configuration
541+ NoBuild = $true
542+ }
543+ if ($TestFilter ) {
544+ $testArgs [" TestFilter" ] = $TestFilter
545+ }
546+
547+ Stop-ConflictingProcesses @cleanupArgs
548+ & " $PSScriptRoot \test.ps1" @testArgs
549+ $script :testExitCode = $LASTEXITCODE
550+ if ($script :testExitCode -eq 1 ) {
551+ # VSTest exit code 1 means tests were skipped (or skipped+failed). test.ps1 prints a
552+ # FAIL summary when there are actual failures, so treat exit code 1 as a warning only
553+ # to avoid failing the build when the only non-passing tests were skipped.
554+ Write-Warning " Test run exited with code 1 (skipped tests or failures). Check test output above for details."
555+ $script :testExitCode = 0
556+ } elseif ($script :testExitCode -ne 0 ) {
557+ Write-Warning " Some tests failed (exit code: $ ( $script :testExitCode ) ). Check output above for details."
558+ }
559+ }
560+
528561 if ($BuildInstaller -or $BuildPatch ) {
529562 if ($BuildPatch ) {
530563 $BaseOrPatch = " Patch"
@@ -575,36 +608,6 @@ try {
575608 Write-Host " [OK] $BaseOrPatch build complete!" - ForegroundColor Green
576609 }
577610 }
578-
579- # =============================================================================
580- # Test Execution (Optional)
581- # =============================================================================
582-
583- if ($RunTests ) {
584- Write-Host " "
585- Write-Host " Running tests..." - ForegroundColor Cyan
586-
587- $testArgs = @ {
588- Configuration = $Configuration
589- NoBuild = $true
590- }
591- if ($TestFilter ) {
592- $testArgs [" TestFilter" ] = $TestFilter
593- }
594-
595- Stop-ConflictingProcesses @cleanupArgs
596- & " $PSScriptRoot \test.ps1" @testArgs
597- $script :testExitCode = $LASTEXITCODE
598- if ($script :testExitCode -eq 1 ) {
599- # VSTest exit code 1 means tests were skipped (or skipped+failed). test.ps1 prints a
600- # FAIL summary when there are actual failures, so treat exit code 1 as a warning only
601- # to avoid failing the build when the only non-passing tests were skipped.
602- Write-Warning " Test run exited with code 1 (skipped tests or failures). Check test output above for details."
603- $script :testExitCode = 0
604- } elseif ($script :testExitCode -ne 0 ) {
605- Write-Warning " Some tests failed (exit code: $ ( $script :testExitCode ) ). Check output above for details."
606- }
607- }
608611}
609612finally {
610613 # Kill any lingering build processes that might hold file locks
0 commit comments