fix: avoid full rebuild by writing BuildVer.h only when content changes

Previously, prebuild.ps1 unconditionally overwrote BuildVer.h on every
build using Set-Content, updating its timestamp even when the content
was identical. This caused MSBuild to treat all files depending on
BuildVer.h as out of date, triggering a full rebuild every time.

Fix: compare the new content with the existing file before writing.
BuildVer.h is now only written if sha, branch, or dev suffix has
actually changed.

Also removed the `git restore` call from postbuild.ps1 as it is no
longer needed.
This commit is contained in:
MrTheShy 2026-03-11 23:16:31 +01:00
parent 1036b7368e
commit b941a27b90
2 changed files with 14 additions and 6 deletions

View file

@ -36,8 +36,6 @@ foreach ($copy in $copies) {
if (Test-Path $src) {
# Copy the files using xcopy, forcing overwrite and suppressing errors, and only copying if the source is newer than the destination
xcopy /q /y /i /s /e /d "$src" "$dst" 2>$null
xcopy /q /y /i /s /e /d "$src" "$dst" 2>$null
}
}
git restore "**/BuildVer.h"
}

View file

@ -27,7 +27,7 @@ if (git status --porcelain) {
$suffix = "-dev"
}
@"
$newContent = @"
#pragma once
#define VER_PRODUCTBUILD $build
@ -35,4 +35,14 @@ if (git status --porcelain) {
#define VER_FILEVERSION_STR_W VER_PRODUCTVERSION_STR_W
#define VER_BRANCHVERSION_STR_W L"$ref"
#define VER_NETWORK VER_PRODUCTBUILD
"@ | Set-Content "Common/BuildVer.h"
"@
$path = "Common/BuildVer.h"
$existing = if (Test-Path $path) { Get-Content $path -Raw } else { "" }
if ($existing.Trim() -ne $newContent.Trim()) {
$newContent | Set-Content $path
Write-Host "BuildVer.h aggiornato."
} else {
Write-Host "BuildVer.h invariato, skip."
}