From 2263ff9bfc0af809a17154c7a02274cb34c51081 Mon Sep 17 00:00:00 2001 From: dotTrench Date: Tue, 13 Jan 2026 19:12:05 +0100 Subject: [PATCH] [Fix] Allow missing solution file Non existent solution files are no longer treated as an error, but rather a warning, this is done to handle cases where a solution file is not present in one of the graphs, but exists in the other graph. Also allows for solution files that don't exist on the current file system, since the solution could be present in either HEAD or BASE and would be evaluated there. --- .../SolutionProjectGraphEntryPointProvider.cs | 4 ++-- src/dotnet-proj-diff/ProjectDiffCommand.cs | 4 ---- ...NewSolutionMarksProjectAsAdded.verified.txt | 7 +++++++ .../ProjectDiff.Tests/Tool/ProjectDiffTests.cs | 18 ++++++++++++++++++ 4 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 test/ProjectDiff.Tests/Tool/ProjectDiffTests.NewSolutionMarksProjectAsAdded.verified.txt diff --git a/src/ProjectDiff.Core/Entrypoints/SolutionProjectGraphEntryPointProvider.cs b/src/ProjectDiff.Core/Entrypoints/SolutionProjectGraphEntryPointProvider.cs index 355b7b3..164542e 100644 --- a/src/ProjectDiff.Core/Entrypoints/SolutionProjectGraphEntryPointProvider.cs +++ b/src/ProjectDiff.Core/Entrypoints/SolutionProjectGraphEntryPointProvider.cs @@ -26,8 +26,8 @@ CancellationToken cancellationToken { if (!fs.FileExists(_solution.FullName)) { - _logger.LogError("Could not find the solution file {SolutionFile} in the file system", _solution.FullName); - throw new FileNotFoundException("Could not find the solution file in the file system", _solution.FullName); + _logger.LogWarning("Could not find the solution file {SolutionFile} in the file system, assuming empty", _solution.FullName); + return []; } await using var stream = fs.GetFileStream( diff --git a/src/dotnet-proj-diff/ProjectDiffCommand.cs b/src/dotnet-proj-diff/ProjectDiffCommand.cs index c32b681..59a4ede 100644 --- a/src/dotnet-proj-diff/ProjectDiffCommand.cs +++ b/src/dotnet-proj-diff/ProjectDiffCommand.cs @@ -35,10 +35,6 @@ public sealed class ProjectDiffCommand : RootCommand { x.AddError("{x.Argument.Name} must be specified"); } - else if (!f.Exists) - { - x.AddError($"File '{f.FullName}' does not exist."); - } else if (f.Extension is not (".sln" or ".slnx")) { x.AddError($"File '{f.FullName}' is not a valid sln file."); diff --git a/test/ProjectDiff.Tests/Tool/ProjectDiffTests.NewSolutionMarksProjectAsAdded.verified.txt b/test/ProjectDiff.Tests/Tool/ProjectDiffTests.NewSolutionMarksProjectAsAdded.verified.txt new file mode 100644 index 0000000..96d7157 --- /dev/null +++ b/test/ProjectDiff.Tests/Tool/ProjectDiffTests.NewSolutionMarksProjectAsAdded.verified.txt @@ -0,0 +1,7 @@ +[ + { + path: Sample/Sample.csproj, + name: Sample, + status: Added + } +] \ No newline at end of file diff --git a/test/ProjectDiff.Tests/Tool/ProjectDiffTests.cs b/test/ProjectDiff.Tests/Tool/ProjectDiffTests.cs index bb50404..c6e28bc 100644 --- a/test/ProjectDiff.Tests/Tool/ProjectDiffTests.cs +++ b/test/ProjectDiff.Tests/Tool/ProjectDiffTests.cs @@ -337,6 +337,24 @@ public async Task DetectsAddedProjectsWithDirectoryScan() await VerifyJson(output); } + [Fact] + public async Task NewSolutionMarksProjectAsAdded() + { + + using var repo = await TestRepository.SetupAsync(static async r => + { + r.CreateDirectory("Sample"); + r.CreateProject("Sample/Sample.csproj"); + await r.WriteAllTextAsync("Sample/MyClass.cs", "// Some content"); + } + ); + + var sln = await repo.CreateSolutionAsync("Sample.sln", sln => sln.AddProject("Sample/Sample.csproj")); + + var output = await ExecuteAndReadStdout(repo, $"--solution={sln}"); + await VerifyJson(output); + } + private static async Task ExecuteAndReadStdout( TestRepository repository, params string[] args