From b941a27b904e872f017cf96217a04925fd41201d Mon Sep 17 00:00:00 2001 From: MrTheShy <49885496+MrTheShy@users.noreply.github.com> Date: Wed, 11 Mar 2026 23:16:31 +0100 Subject: [PATCH] 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. --- Minecraft.Client/postbuild.ps1 | 6 ++---- Minecraft.Client/prebuild.ps1 | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Minecraft.Client/postbuild.ps1 b/Minecraft.Client/postbuild.ps1 index 8ffc9b98b..6d2bda12b 100644 --- a/Minecraft.Client/postbuild.ps1 +++ b/Minecraft.Client/postbuild.ps1 @@ -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" \ No newline at end of file +} \ No newline at end of file diff --git a/Minecraft.Client/prebuild.ps1 b/Minecraft.Client/prebuild.ps1 index 0acbf023b..99078e9e5 100644 --- a/Minecraft.Client/prebuild.ps1 +++ b/Minecraft.Client/prebuild.ps1 @@ -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." +} \ No newline at end of file