-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix dotnet-run-file up-to-date checks across symlinks #52064
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jjonescz
merged 3 commits into
dotnet:release/10.0.2xx
from
jjonescz:sprint-alias-caching
Dec 11, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1021,6 +1021,62 @@ public void DirectoryBuildProps() | |
| .And.HaveStdOut("Hello from TestName"); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Implicit build files are taken from the folder of the symbolic link itself, not its target. | ||
| /// This is equivalent to the behavior of symlinked project files. | ||
| /// See <see href="https://github.com/dotnet/sdk/pull/52064#issuecomment-3628958688"/>. | ||
| /// </summary> | ||
| [Fact] | ||
| public void DirectoryBuildProps_SymbolicLink() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| { | ||
| var testInstance = _testAssetsManager.CreateTestDirectory(); | ||
|
|
||
| var dir1 = Path.Join(testInstance.Path, "dir1"); | ||
| Directory.CreateDirectory(dir1); | ||
|
|
||
| var originalPath = Path.Join(dir1, "original.cs"); | ||
| File.WriteAllText(originalPath, s_program); | ||
|
|
||
| File.WriteAllText(Path.Join(dir1, "Directory.Build.props"), """ | ||
| <Project> | ||
| <PropertyGroup> | ||
| <AssemblyName>OriginalAssemblyName</AssemblyName> | ||
| </PropertyGroup> | ||
| </Project> | ||
| """); | ||
|
|
||
| var dir2 = Path.Join(testInstance.Path, "dir2"); | ||
| Directory.CreateDirectory(dir2); | ||
|
|
||
| var programFileName = "linked.cs"; | ||
| var programPath = Path.Join(dir2, programFileName); | ||
|
|
||
| File.CreateSymbolicLink(path: programPath, pathToTarget: originalPath); | ||
|
|
||
| File.WriteAllText(Path.Join(dir2, "Directory.Build.props"), """ | ||
| <Project> | ||
| <PropertyGroup> | ||
| <AssemblyName>LinkedAssemblyName</AssemblyName> | ||
| </PropertyGroup> | ||
| </Project> | ||
| """); | ||
|
|
||
| new DotnetCommand(Log, "run", programFileName) | ||
| .WithWorkingDirectory(dir2) | ||
| .Execute() | ||
| .Should().Pass() | ||
| .And.HaveStdOut("Hello from LinkedAssemblyName"); | ||
|
|
||
| // Removing the Directory.Build.props should be detected by up-to-date check. | ||
| File.Delete(Path.Join(dir2, "Directory.Build.props")); | ||
|
|
||
| new DotnetCommand(Log, "run", programFileName) | ||
| .WithWorkingDirectory(dir2) | ||
| .Execute() | ||
| .Should().Pass() | ||
| .And.HaveStdOut("Hello from linked"); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Overriding default (implicit) properties of file-based apps via implicit build files. | ||
| /// </summary> | ||
|
|
@@ -3403,6 +3459,82 @@ public void UpToDate_InvalidOptions() | |
| .And.HaveStdErrContaining(string.Format(CliCommandStrings.CannotCombineOptions, RunCommandParser.NoCacheOption.Name, RunCommandParser.NoBuildOption.Name)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// <see cref="UpToDate"/> optimization should see through symlinks. | ||
| /// See <see href="https://github.com/dotnet/sdk/issues/52063"/>. | ||
| /// </summary> | ||
| [Fact] | ||
| public void UpToDate_SymbolicLink() | ||
| { | ||
| var testInstance = _testAssetsManager.CreateTestDirectory(); | ||
|
|
||
| var originalPath = Path.Join(testInstance.Path, "original.cs"); | ||
| var code = """ | ||
| #!/usr/bin/env dotnet | ||
| Console.WriteLine("v1"); | ||
| """; | ||
| var utf8NoBom = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false); | ||
| File.WriteAllText(originalPath, code, utf8NoBom); | ||
|
|
||
| var programFileName = "linked"; | ||
| var programPath = Path.Join(testInstance.Path, programFileName); | ||
|
|
||
| File.CreateSymbolicLink(path: programPath, pathToTarget: originalPath); | ||
|
|
||
| // Remove artifacts from possible previous runs of this test. | ||
| var artifactsDir = VirtualProjectBuildingCommand.GetArtifactsPath(programPath); | ||
| if (Directory.Exists(artifactsDir)) Directory.Delete(artifactsDir, recursive: true); | ||
|
|
||
| Build(testInstance, BuildLevel.All, expectedOutput: "v1", programFileName: programFileName); | ||
|
|
||
| Build(testInstance, BuildLevel.None, expectedOutput: "v1", programFileName: programFileName); | ||
|
|
||
| code = code.Replace("v1", "v2"); | ||
| File.WriteAllText(originalPath, code, utf8NoBom); | ||
|
|
||
| Build(testInstance, BuildLevel.Csc, expectedOutput: "v2", programFileName: programFileName); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Similar to <see cref="UpToDate_SymbolicLink"/> but with a chain of symlinks. | ||
| /// </summary> | ||
| [Fact] | ||
| public void UpToDate_SymbolicLink2() | ||
| { | ||
| var testInstance = _testAssetsManager.CreateTestDirectory(); | ||
|
|
||
| var originalPath = Path.Join(testInstance.Path, "original.cs"); | ||
| var code = """ | ||
| #!/usr/bin/env dotnet | ||
| Console.WriteLine("v1"); | ||
| """; | ||
| var utf8NoBom = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false); | ||
| File.WriteAllText(originalPath, code, utf8NoBom); | ||
|
|
||
| var intermediateFileName = "linked1"; | ||
| var intermediatePath = Path.Join(testInstance.Path, intermediateFileName); | ||
|
|
||
| File.CreateSymbolicLink(path: intermediatePath, pathToTarget: originalPath); | ||
|
|
||
| var programFileName = "linked2"; | ||
| var programPath = Path.Join(testInstance.Path, programFileName); | ||
|
|
||
| File.CreateSymbolicLink(path: programPath, pathToTarget: intermediatePath); | ||
|
|
||
| // Remove artifacts from possible previous runs of this test. | ||
| var artifactsDir = VirtualProjectBuildingCommand.GetArtifactsPath(programPath); | ||
| if (Directory.Exists(artifactsDir)) Directory.Delete(artifactsDir, recursive: true); | ||
|
|
||
| Build(testInstance, BuildLevel.All, expectedOutput: "v1", programFileName: programFileName); | ||
|
|
||
| Build(testInstance, BuildLevel.None, expectedOutput: "v1", programFileName: programFileName); | ||
|
|
||
| code = code.Replace("v1", "v2"); | ||
| File.WriteAllText(originalPath, code, utf8NoBom); | ||
|
|
||
| Build(testInstance, BuildLevel.Csc, expectedOutput: "v2", programFileName: programFileName); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Up-to-date checks and optimizations currently don't support other included files. | ||
| /// </summary> | ||
|
|
@@ -3712,6 +3844,41 @@ Hello from Program | |
| """); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Combination of <see cref="UpToDate_SymbolicLink"/> and <see cref="CscOnly"/>. | ||
| /// </summary> | ||
| [Fact] | ||
| public void CscOnly_SymbolicLink() | ||
| { | ||
| var testInstance = _testAssetsManager.CreateTestDirectory(baseDirectory: OutOfTreeBaseDirectory); | ||
|
|
||
| var originalPath = Path.Join(testInstance.Path, "original.cs"); | ||
| var code = """ | ||
| #!/usr/bin/env dotnet | ||
| Console.WriteLine("v1"); | ||
| """; | ||
| var utf8NoBom = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false); | ||
| File.WriteAllText(originalPath, code, utf8NoBom); | ||
|
|
||
| var programFileName = "linked"; | ||
| var programPath = Path.Join(testInstance.Path, programFileName); | ||
|
|
||
| File.CreateSymbolicLink(path: programPath, pathToTarget: originalPath); | ||
|
|
||
| // Remove artifacts from possible previous runs of this test. | ||
| var artifactsDir = VirtualProjectBuildingCommand.GetArtifactsPath(programPath); | ||
| if (Directory.Exists(artifactsDir)) Directory.Delete(artifactsDir, recursive: true); | ||
|
|
||
| Build(testInstance, BuildLevel.Csc, expectedOutput: "v1", programFileName: programFileName); | ||
|
|
||
| Build(testInstance, BuildLevel.None, expectedOutput: "v1", programFileName: programFileName); | ||
|
|
||
| code = code.Replace("v1", "v2"); | ||
| File.WriteAllText(originalPath, code, utf8NoBom); | ||
|
|
||
| Build(testInstance, BuildLevel.Csc, expectedOutput: "v2", programFileName: programFileName); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Tests an optimization which remembers CSC args from prior MSBuild runs and can skip subsequent MSBuild invocations and call CSC directly. | ||
| /// This optimization kicks in when the file has some <c>#:</c> directives (then the simpler "hard-coded CSC args" optimization cannot be used). | ||
|
|
@@ -3871,6 +4038,40 @@ public void CscOnly_AfterMSBuild_HardLinks() | |
| Build(testInstance, BuildLevel.Csc, expectedOutput: "Hi from Program"); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Combination of <see cref="UpToDate_SymbolicLink"/> and <see cref="CscOnly_AfterMSBuild"/>. | ||
| /// </summary> | ||
| [Fact] | ||
| public void CscOnly_AfterMSBuild_SymbolicLink() | ||
| { | ||
| var testInstance = _testAssetsManager.CreateTestDirectory(baseDirectory: OutOfTreeBaseDirectory); | ||
|
|
||
| var originalPath = Path.Join(testInstance.Path, "original.cs"); | ||
| var code = """ | ||
| #!/usr/bin/env dotnet | ||
| #:property Configuration=Release | ||
| Console.WriteLine("v1"); | ||
| """; | ||
| var utf8NoBom = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false); | ||
| File.WriteAllText(originalPath, code, utf8NoBom); | ||
|
|
||
| var programFileName = "linked"; | ||
| var programPath = Path.Join(testInstance.Path, programFileName); | ||
|
|
||
| File.CreateSymbolicLink(path: programPath, pathToTarget: originalPath); | ||
|
|
||
| // Remove artifacts from possible previous runs of this test. | ||
| var artifactsDir = VirtualProjectBuildingCommand.GetArtifactsPath(programPath); | ||
| if (Directory.Exists(artifactsDir)) Directory.Delete(artifactsDir, recursive: true); | ||
|
|
||
| Build(testInstance, BuildLevel.All, expectedOutput: "v1", programFileName: programFileName); | ||
|
|
||
| code = code.Replace("v1", "v2"); | ||
| File.WriteAllText(originalPath, code, utf8NoBom); | ||
|
|
||
| Build(testInstance, BuildLevel.Csc, expectedOutput: "v2", programFileName: programFileName); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// See <see cref="CscOnly_AfterMSBuild"/>. | ||
| /// This optimization currently does not support <c>#:project</c> references and hence is disabled if those are present. | ||
|
|
@@ -4398,6 +4599,35 @@ public void EntryPointFilePath_WithUnicodeCharacters() | |
| .And.HaveStdOut($"EntryPointFilePath: {filePath}"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void EntryPointFilePath_SymbolicLink() | ||
| { | ||
| var testInstance = _testAssetsManager.CreateTestDirectory(); | ||
| var fileName = "Program.cs"; | ||
| var programPath = Path.Join(testInstance.Path, fileName); | ||
| File.WriteAllText(programPath, """ | ||
| #!/usr/bin/env dotnet | ||
| var entryPointFilePath = AppContext.GetData("EntryPointFilePath") as string; | ||
| Console.WriteLine($"EntryPointFilePath: {entryPointFilePath}"); | ||
| """); | ||
|
|
||
| new DotnetCommand(Log, "run", fileName) | ||
| .WithWorkingDirectory(testInstance.Path) | ||
| .Execute() | ||
| .Should().Pass() | ||
| .And.HaveStdOut($"EntryPointFilePath: {programPath}"); | ||
|
|
||
| var linkName = "linked"; | ||
| var linkPath = Path.Join(testInstance.Path, linkName); | ||
| File.CreateSymbolicLink(linkPath, programPath); | ||
|
|
||
| new DotnetCommand(Log, "run", linkName) | ||
| .WithWorkingDirectory(testInstance.Path) | ||
| .Execute() | ||
| .Should().Pass() | ||
| .And.HaveStdOut($"EntryPointFilePath: {linkPath}"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void MSBuildGet_Simple() | ||
| { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
returnFinalTargetbehavior, e.g. symlink2 links to symlink1 links to original file, ensuring that symlink2 has correct up to date behavior with respect to original file.