param ( [string]$Configuration = "Release", [string]$Platform = "x64", [string]$Target = "Build", [string]$Verbosity = "Normal", [string]$InstallDirectory = "", [string[]]$InstallFileExtensions = @(".dll", ".exe") ) if (-not $IsWindows) { throw "Build_All_With_MSBuild.ps1 is only supported on Windows because it invokes MSBuild for Visual Studio projects." } $Projects = @( "AccessibleDescriptionAndHelpExample\trunk\AccessibleDescriptionAndHelpExample.sln" "Clock\trunk\Clock.sln" "cmdLauncher\trunk\cmdLauncher.sln" "DialogWithRequiredState\trunk\DialogWithRequiredState.sln" "DigClock\trunk\DigClock.sln" "GetStartTime\trunk\GetStartTime.sln" "Implementing-An-Accessibility-Server\Windows-API-Accessibility-Server\trunk\Windows-API-Accessibility-Server.sln" "ImportCertificate\trunk\ImportCertificate.sln" "KeyView\trunk\KeyView.sln" "MMNotificationClientTest\trunk\MMNotificationClientTest.sln" "NETFrameworkVersionLister\trunk\NETFrameworkVersionLister.sln" "now\trunk\now.sln" "PlaySound\trunk\PlaySound.sln" "SkeletonWin32App\trunk\SkeletonWin32App.sln" "StartSuspended\trunk\StartSuspended.sln" "wxNotepad\trunk\wxNotepad.sln" "yekneb\trunk\yekneb.sln" ) function Build-Project { param ( [string]$ProjectPath, [string]$ProjectConfiguration = "Release", [string]$ProjectPlatform = "x64", [string]$ProjectTarget = "Build", [string]$ProjectVerbosity = "Normal", [string]$ProjectInstallDirectory = "" ) $ProjectName = Split-Path -Path $ProjectPath -LeafBase $ProjectDirectory = Split-Path -Path $ProjectPath -Parent if (-not (Test-Path -Path $ProjectPath)) { throw "Project path not found: $ProjectPath" } Write-Host "Building project: $ProjectName" Push-Location -Path $ProjectDirectory try { & msbuild "-nologo" "$ProjectPath" "-property:Configuration=$ProjectConfiguration;Platform=$ProjectPlatform" "-target:$ProjectTarget" "-detailedSummary" "-maxCpuCount" "-verbosity:$ProjectVerbosity" 2>&1 | ForEach-Object { Write-Information $_ -InformationAction Continue } $msbuildExitCode = $LASTEXITCODE if ($msbuildExitCode -ne 0) { throw "Build failed for project: $ProjectName (exit code: $msbuildExitCode)" } } finally { Pop-Location } } function Get-PlatformShortName { param ( [string]$ProjectPlatform ) switch ($ProjectPlatform.ToLowerInvariant()) { "win32" { return "x86" } "x86" { return "x86" } "x64" { return "x64" } "anycpu" { return "AnyCPU" } default { return $ProjectPlatform } } } function Install-ProjectOutput { param ( [string]$ProjectPath, [string]$ProjectConfiguration, [string]$ProjectPlatform, [string]$ProjectInstallDirectory, [string[]]$ProjectInstallFileExtensions = @(".dll", ".exe") ) if ([string]::IsNullOrWhiteSpace($ProjectInstallDirectory)) { return } $AllowedExtensions = @($ProjectInstallFileExtensions | Where-Object { -not [string]::IsNullOrWhiteSpace($_) } | ForEach-Object { $Extension = $_.Trim().ToLowerInvariant() if ($Extension.StartsWith(".")) { $Extension } else { "." + $Extension } } | Select-Object -Unique) if ($AllowedExtensions.Count -eq 0) { Write-Warning "No install file extensions configured, skipping install." return } $ProjectDirectory = Split-Path -Path $ProjectPath -Parent $PlatformShortName = Get-PlatformShortName -ProjectPlatform $ProjectPlatform $SourceDirectory = Join-Path -Path $ProjectDirectory -ChildPath "build\out\$PlatformShortName\$ProjectConfiguration" $DestinationDirectory = Join-Path -Path $ProjectInstallDirectory -ChildPath "msvc-bin" if (-not (Test-Path -Path $SourceDirectory)) { Write-Warning "Output directory not found, skipping install: $SourceDirectory" return } New-Item -Path $DestinationDirectory -ItemType Directory -Force | Out-Null $FilesToInstall = @(Get-ChildItem -Path $SourceDirectory -File -Recurse | Where-Object { $AllowedExtensions -contains $_.Extension.ToLowerInvariant() }) foreach ($FileToInstall in $FilesToInstall) { Copy-Item -Path $FileToInstall.FullName -Destination $DestinationDirectory -Force } Write-Host "Installed $($FilesToInstall.Count) file(s) from $SourceDirectory to $DestinationDirectory" } function Build-TTSApp { param ( [string]$ProjectConfiguration = "Release", [string]$ProjectPlatform = "x64", [string]$ProjectTarget = "Build", [string]$ProjectVerbosity = "Normal", [string]$ProjectInstallDirectory = "", [string[]]$ProjectInstallFileExtensions = @(".dll", ".exe") ) $TTSAppProjectPath = Join-Path -Path $PSScriptRoot -ChildPath "TTSApp\trunk\TTSApp.sln" $TTSAppProjectConfiguration = "$ProjectConfiguration-SAPI" Build-Project -ProjectPath $TTSAppProjectPath -ProjectConfiguration $TTSAppProjectConfiguration -ProjectPlatform $ProjectPlatform -ProjectTarget $ProjectTarget -ProjectVerbosity $ProjectVerbosity -ProjectInstallDirectory $ProjectInstallDirectory Install-ProjectOutput -ProjectPath $TTSAppProjectPath -ProjectConfiguration $TTSAppProjectConfiguration -ProjectPlatform $ProjectPlatform -ProjectInstallDirectory $ProjectInstallDirectory -ProjectInstallFileExtensions $ProjectInstallFileExtensions $MicrosoftSpeechSDKPath = "${env:ProgramFiles}\Microsoft SDKs\Speech\v11.0" $MicrosoftSpeechSDKX86Path = "${env:ProgramFiles(x86)}\Microsoft SDKs\Speech\v11.0" if ((Test-Path -Path $MicrosoftSpeechSDKPath) -and (Test-Path -Path $MicrosoftSpeechSDKX86Path)) { $TTSAppProjectConfiguration = "$ProjectConfiguration-MicrosoftSpeechPlatform" Build-Project -ProjectPath $TTSAppProjectPath -ProjectConfiguration $TTSAppProjectConfiguration -ProjectPlatform $ProjectPlatform -ProjectTarget $ProjectTarget -ProjectVerbosity $ProjectVerbosity -ProjectInstallDirectory $ProjectInstallDirectory Install-ProjectOutput -ProjectPath $TTSAppProjectPath -ProjectConfiguration $TTSAppProjectConfiguration -ProjectPlatform $ProjectPlatform -ProjectInstallDirectory $ProjectInstallDirectory -ProjectInstallFileExtensions $ProjectInstallFileExtensions } } if ([string]::IsNullOrWhiteSpace($InstallDirectory)) { $HomeDirectory = if (-not [string]::IsNullOrWhiteSpace($env:HOME)) { $env:HOME } else { $HOME } $InstallDirectory = Join-Path -Path $HomeDirectory -ChildPath ".local" } New-Item -Path $InstallDirectory -ItemType Directory -Force | Out-Null $buildSucceeded = $true foreach ($project in $Projects) { $ProjectPath = Join-Path -Path $PSScriptRoot -ChildPath $project try { Build-Project -ProjectPath $ProjectPath -ProjectConfiguration $Configuration -ProjectPlatform $Platform -ProjectTarget $Target -ProjectVerbosity $Verbosity -ProjectInstallDirectory $InstallDirectory Install-ProjectOutput -ProjectPath $ProjectPath -ProjectConfiguration $Configuration -ProjectPlatform $Platform -ProjectInstallDirectory $InstallDirectory -ProjectInstallFileExtensions $InstallFileExtensions } catch { Write-Error $_ Write-Error "Stopping build loop because project failed: $project" $buildSucceeded = $false break } } if ($buildSucceeded) { try { Build-TTSApp -ProjectConfiguration $Configuration -ProjectPlatform $Platform -ProjectTarget $Target -ProjectVerbosity $Verbosity -ProjectInstallDirectory $InstallDirectory -ProjectInstallFileExtensions $InstallFileExtensions } catch { Write-Error $_ $buildSucceeded = $false } } if ($buildSucceeded) { Write-Host "All projects built successfully." exit 0 } else { Write-Error "One or more projects failed to build." exit 1 }