You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MsBuild using last write time of symlinks instead of their targets to determine whether or not to rebuild #13465
On non-Windows platforms, if one of the source files is a symlink, and the symlink target is modified, MsBuild doesn't recognize the change and doesn't rebuild the target.
Steps to Reproduce
I reproduced this issue on MacOS, although I suspect that the problem is the same on all non-Windows platforms.
Shell code to reproduce from scratch (run in a new folder):
#!/bin/sh -e
dotnet new create console -lang:'C#'
mv Program.cs Program.txt
ln -s Program.txt Program.cs
# At this point Program.cs is a symlink to Program.txt, which is not directly part of the build
dotnet build -c:Debug
stat bin/Debug/net*/*.dll # To get the last modification time of the built DLL
sleep 2
touch Program.txt # "Update" the target
dotnet build -c:Debug
stat bin/Debug/net*/*.dll # Same last modification time -> hasn't been rebuilt
sleep 2
rm Program.cs
ln -s Program.txt Program.cs # "Update" the symlink
dotnet build -c:Debug
stat bin/Debug/net*/*.dll # Different last modification time -> has been rebuilt
Expected Behavior
I would expect the assembly to be actually built the 1st and 2nd run.
See also #826 and #322.
I believe the problem is here, where unlike in the isWindows if branch it doesn't check if the path points to a symlink.
It would be nice at least to be able to force link resolution by setting MSBUILDALWAYSCHECKCONTENTTIMESTAMP to 1, which sets EscapeHatches.AlwaysUseContentTimestamp to true, or even better if it just "did the right thing" like on Windows.
Also, when the target of the symlink changes, MSBuild doesn't detect that (if the new target is older, MSBuild thinks that everything is up to date). This currently happens only on Windows, probably because on Windows, MSBuild looks at timestamp of the link target (so it detects the target content changes, but not when the link's target changes) whereas on Linux, MSBuild looks at timestamp of the link itself (so it detects exactly the opposite).
Btw, when fixing this, also consider there can be a chain of symlinks.
Activity
jjonescz commentedon Sep 2, 2026
Also, when the target of the symlink changes, MSBuild doesn't detect that (if the new target is older, MSBuild thinks that everything is up to date). This currently happens only on Windows, probably because on Windows, MSBuild looks at timestamp of the link target (so it detects the target content changes, but not when the link's target changes) whereas on Linux, MSBuild looks at timestamp of the link itself (so it detects exactly the opposite).
Btw, when fixing this, also consider there can be a chain of symlinks.