Skip to content

Conversation

@jjonescz
Copy link
Member

@jjonescz jjonescz commented Dec 8, 2025

Fixes #52063.

@jjonescz jjonescz requested a review from Copilot December 8, 2025 15:17
@jjonescz jjonescz added the Area-run-file Items related to the "dotnet run <file>" effort label Dec 8, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an issue where dotnet run with file-based programs incorrectly treated files as up-to-date when they were modified through symbolic links. The fix ensures that timestamp checks resolve symlinks to their final targets, so modifications to the target file are properly detected.

Key changes:

  • Added ResolveLinkTarget helper to resolve symlinks before checking file modification times
  • Applied the fix to both entry point files and implicit build files
  • Added comprehensive test coverage for symlink scenarios

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs Added symlink resolution logic to up-to-date checks, resolving both entry point and implicit build files to their final targets before comparing timestamps
test/dotnet.Tests/CommandTests/Run/RunFileTests.cs Added four new test cases covering symlink scenarios: basic up-to-date checks, CSC-only optimization, CSC-after-MSBuild optimization, and EntryPointFilePath behavior with symlinks


return false;

static FileSystemInfo ResolveLinkTarget(FileSystemInfo fileSystemInfo)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps ResolveLinkTargetOrSelf, to differentiate from FileSystemInfo.ResolveLinkTarget?


static FileSystemInfo ResolveLinkTarget(FileSystemInfo fileSystemInfo)
{
return fileSystemInfo.ResolveLinkTarget(returnFinalTarget: true) ?? fileSystemInfo;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to exercise the returnFinalTarget behavior, e.g. symlink2 links to symlink1 links to original file, ensuring that symlink2 has correct up to date behavior with respect to original file.

@RikkiGibson
Copy link
Member

What is the behavior of symlinks with respect to implicit build files?

Is it expected that different implicit build files would be brought in, when running dotnet build app/app.cs versus dotnet build link/app?

.
├───app
│       app.cs
│       Directory.Build.props
│
└───link
        app (symlink to ../app/app.cs)
        Directory.Build.props

I would personally find it a bit strange if the different invocations used different implicit build files. My hope would be that we would resolve the symlink very early on in this process, and consistently use the same "implicit build files" whether we are building the symlink or the original thing.

It might also be worth checking what dotnet build MyProjectSymlink.csproj does.

Possibly the behavior I am asking for is already present and I missed it. Apologies if that is the case.

@jjonescz
Copy link
Member Author

jjonescz commented Dec 10, 2025

It might also be worth checking what dotnet build MyProjectSymlink.csproj does.

If the project is symlinked, it's as if it was copied (so dir.build.props are taken from the symlink's directory, not its target; i.e., different build files are brought in for dotnet build original.csproj and dotnet build linked.csproj, but that looks expected to me in this case). I'm not sure file-based apps should have the same behavior, but they currently do. It feels like an orthogonal issue though. But I can add a test.

/// See <see href="https://github.com/dotnet/sdk/pull/52064#issuecomment-3628958688"/>.
/// </summary>
[Fact]
public void DirectoryBuildProps_SymbolicLink()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for adding the test. I think no need to change behavior in this PR. We can see if anyone complains about this behavior during the upcoming dev cycle, and decide at that point whether there is motivation to make a change.

@jjonescz jjonescz requested a review from MiYanni December 10, 2025 19:07
@jjonescz
Copy link
Member Author

/ba-g known failures

@jjonescz jjonescz merged commit 82acc88 into dotnet:release/10.0.2xx Dec 11, 2025
21 of 26 checks passed
@jjonescz jjonescz deleted the sprint-alias-caching branch December 11, 2025 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-run-file Items related to the "dotnet run <file>" effort

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants