|
| 1 | +function Get-SolutionDirectory { |
| 2 | + param ([string]$StartPath = $(Get-Location)) |
| 3 | + |
| 4 | + $currentPath = $StartPath |
| 5 | + while ($true) { |
| 6 | + if (Test-Path (Join-Path $currentPath "FixedMathSharp.sln")) { |
| 7 | + return $currentPath |
| 8 | + } |
| 9 | + $parent = [System.IO.Directory]::GetParent($currentPath) |
| 10 | + if ($parent -eq $null) { break } |
| 11 | + $currentPath = $parent.FullName |
| 12 | + } |
| 13 | + throw "Solution directory not found." |
| 14 | +} |
| 15 | + |
| 16 | +function Ensure-GitVersion-Environment { |
| 17 | + param ([string]$UnityVersion = "2022.3.20f1") |
| 18 | + |
| 19 | + # Ensure GitVersion is installed and available |
| 20 | + if (-not (Get-Command "dotnet-gitversion" -ErrorAction SilentlyContinue)) { |
| 21 | + Write-Host "GitVersion is not installed. Install it with:" |
| 22 | + Write-Host "dotnet tool install -g GitVersion.Tool" |
| 23 | + exit 1 |
| 24 | + } |
| 25 | + |
| 26 | + Write-Host "Fetching version information using GitVersion..." |
| 27 | + |
| 28 | + # Capture GitVersion output as JSON and convert it to PowerShell objects |
| 29 | + $gitVersionOutput = dotnet-gitversion -output json | ConvertFrom-Json |
| 30 | + |
| 31 | + if ($null -eq $gitVersionOutput) { |
| 32 | + Write-Host "ERROR: Failed to get version information from GitVersion." -ForegroundColor Red |
| 33 | + exit 1 |
| 34 | + } |
| 35 | + |
| 36 | + # Extract key version properties |
| 37 | + $semVer = $gitVersionOutput.FullSemVer |
| 38 | + $assemblySemVer = $gitVersionOutput.AssemblySemVer |
| 39 | + $assemblySemFileVer = $gitVersionOutput.AssemblySemFileVer |
| 40 | + $infoVersion = $gitVersionOutput.InformationalVersion |
| 41 | + |
| 42 | + # Set environment variables for the build process |
| 43 | + [System.Environment]::SetEnvironmentVariable('GitVersion_FullSemVer', $semVer, 'Process') |
| 44 | + [System.Environment]::SetEnvironmentVariable('GitVersion_AssemblySemVer', $assemblySemVer, 'Process') |
| 45 | + [System.Environment]::SetEnvironmentVariable('GitVersion_AssemblySemFileVer', $assemblySemFileVer, 'Process') |
| 46 | + [System.Environment]::SetEnvironmentVariable('GitVersion_InformationalVersion', $infoVersion, 'Process') |
| 47 | + [System.Environment]::SetEnvironmentVariable('UnityVersion', $UnityVersion, 'Process') |
| 48 | + |
| 49 | + Write-Host "Environment variables set:" |
| 50 | + Write-Host " GitVersion_FullSemVer = $semVer" |
| 51 | + Write-Host " GitVersion_AssemblySemVer = $assemblySemVer" |
| 52 | + Write-Host " GitVersion_AssemblySemFileVer = $assemblySemFileVer" |
| 53 | + Write-Host " GitVersion_InformationalVersion = $infoVersion" |
| 54 | + Write-Host " UnityVersion = $UnityVersion" |
| 55 | +} |
| 56 | + |
| 57 | +function Build-Project { |
| 58 | + param ( |
| 59 | + [string]$SolutionPath = "FixedMathSharp.sln", |
| 60 | + [string]$Configuration = "Release" |
| 61 | + ) |
| 62 | + |
| 63 | + Write-Host "Building $SolutionPath in $Configuration mode..." |
| 64 | + # Clean and build the project with the selected configuration |
| 65 | + dotnet clean |
| 66 | + dotnet build $SolutionPath -c $Configuration |
| 67 | + |
| 68 | + if ($LASTEXITCODE -ne 0) { |
| 69 | + Write-Host "Build failed." -ForegroundColor Red |
| 70 | + exit 1 |
| 71 | + } |
| 72 | + |
| 73 | + Write-Host "Build succeeded!" -ForegroundColor Green |
| 74 | +} |
0 commit comments