MSBuild incremental build error: output considered up to date despite source changes
0 reputation · 13 Sept 2025, 13:45 UTC
0 reputation · 13 Sept 2025, 13:45 UTC
The goal is to understand how MSBuild’s incremental build logic reacts to changes in the operating system’s time zone, and whether a normalization to UTC is necessary to prevent spurious rebuilds.
MSBuild compares source file last‑write timestamps against output timestamps to decide if a project is up to date. On Windows, these timestamps are typically interpreted in the local time zone. Altering the system time zone or moving a workspace between machines in different zones can reorder these timestamps, potentially causing MSBuild to rebuild unchanged projects or skip necessary rebuilds. The current Visual Studio releases expose no user‑visible setting to enforce UTC normalization for these comparisons.
34775 reputation · 13 Sept 2025, 19:01 UTC
MSBuild determines if a target is up to date by comparing file timestamps interpreted in the local time zone. There is currently no documented build property or command-line switch to force MSBuild to normalize these comparisons to UTC.
While the NTFS file system stores timestamps in UTC, the Windows API typically presents these values as local time. MSBuild relies on these API calls to perform its incremental build checks. Consequently, if the system time zone is altered or a workspace is moved between machines in different zones, the relative order of "last-write" timestamps can shift.
This behavior is consistent across both SDK-style and legacy C# projects, as both rely on the same underlying timestamp comparison logic for file-based dependencies. If a source file's local timestamp appears older than the output file due to a time zone shift, MSBuild will incorrectly consider the project up to date, skipping necessary recompilation.
To diagnose and resolve timestamp discrepancies, use the following steps:
msbuild /verbosity:diagnostic
Get-ChildItem | Select-Object Name, LastWriteTime, LastWriteTimeUtc
msbuild /t:Clean,Build
Are you utilizing a network share (SMB/NFS) for your source or output directories? Network file systems can introduce additional timestamp resolution issues or clock skew that may exacerbate time zone discrepancies.
Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 13 Sept 2025, 14:01 UTC
MSBuild relies on the file system's LastWriteTime to determine incremental build status. While NTFS stores these timestamps in UTC, the APIs used to retrieve them often interpret them through the system's local time zone. If the system time zone is shifted backward, a source file's local representation may appear older than the existing output file, causing MSBuild to skip a necessary rebuild.
There is currently no native MSBuild property or command-line switch to force UTC normalization for these specific comparisons. To mitigate this in cross-timezone environments or CI/CD pipelines, developers often have to use the clean target or ensure all build agents are synchronized to UTC to prevent spurious 'up-to-date' errors or de-optimized builds.