@@ -47,10 +47,11 @@ function Get-LatestGitTag {
4747 Write-Host " Fetching latest tags from remote..." - ForegroundColor Yellow
4848 git fetch -- tags 2>&1 | Out-Null
4949
50- # Get the latest tag (sorted by version)
51- $latestTag = git describe -- tags -- abbrev= 0 2>&1
50+ # Get the latest tag sorted by version number (descending)
51+ # Using -v:refname ensures proper semantic version sorting
52+ $latestTag = git tag - l -- sort=- v:refname | Select-Object - First 1
5253
53- if ($LASTEXITCODE -ne 0 ) {
54+ if (-not $latestTag ) {
5455 throw " No git tags found in repository"
5556 }
5657
@@ -115,7 +116,7 @@ function Update-PackageJson {
115116 return $true
116117}
117118
118- # Function to update .csproj file
119+ # Function to update .csproj file (simple <Version> element)
119120function Update-CsprojFile {
120121 param (
121122 [string ]$FilePath ,
@@ -157,6 +158,49 @@ function Update-CsprojFile {
157158 return $true
158159}
159160
161+ # Function to update WiX project file (conditional <Version> element)
162+ function Update-WixProjFile {
163+ param (
164+ [string ]$FilePath ,
165+ [string ]$NewVersion ,
166+ [switch ]$DryRun
167+ )
168+
169+ if (-not (Test-Path $FilePath )) {
170+ Write-Warning " File not found: $FilePath "
171+ return $false
172+ }
173+
174+ $content = Get-Content $FilePath - Raw
175+ $fileName = Split-Path $FilePath - Leaf
176+
177+ # Match Version element with Condition attribute (WiX default version pattern)
178+ # Pattern: <Version Condition="'$(Version)' == ''">X.Y.Z</Version>
179+ if ($content -notmatch ' <Version\s+Condition="[^"]*">([^<]*)</Version>' ) {
180+ Write-Warning " $fileName `: No conditional <Version> element found"
181+ return $false
182+ }
183+
184+ $oldVersion = $Matches [1 ]
185+
186+ if ($oldVersion -eq $NewVersion ) {
187+ Write-Host " $fileName `: Already at version $NewVersion " - ForegroundColor Green
188+ return $true
189+ }
190+
191+ if ($DryRun ) {
192+ Write-Host " $fileName `: Would update $oldVersion -> $NewVersion " - ForegroundColor Yellow
193+ return $true
194+ }
195+
196+ # Update version while preserving the Condition attribute
197+ $updatedContent = $content -replace ' (<Version\s+Condition="[^"]*">)[^<]*(</Version>)' , " `$ {1}$NewVersion `$ {2}"
198+
199+ Set-Content - Path $FilePath - Value $updatedContent - NoNewline
200+ Write-Host " $fileName `: Updated $oldVersion -> $NewVersion " - ForegroundColor Green
201+ return $true
202+ }
203+
160204# Main execution
161205try {
162206 Write-Host " "
@@ -192,6 +236,10 @@ try {
192236 @ {
193237 Path = Join-Path $RepoRoot " Src\GhostDraw\GhostDraw.csproj"
194238 Type = " Csproj"
239+ },
240+ @ {
241+ Path = Join-Path $RepoRoot " Installer\GhostDraw.Installer.wixproj"
242+ Type = " WixProj"
195243 }
196244 )
197245
@@ -206,6 +254,9 @@ try {
206254 " Csproj" {
207255 $result = Update-CsprojFile - FilePath $file.Path - NewVersion $version - DryRun:$DryRun
208256 }
257+ " WixProj" {
258+ $result = Update-WixProjFile - FilePath $file.Path - NewVersion $version - DryRun:$DryRun
259+ }
209260 }
210261 if (-not $result ) {
211262 $success = $false
0 commit comments