Skip to content

Pick the solution named after its directory, else the ordinally first [patch] - #96

Open
matt-edmondson wants to merge 1 commit into
mainfrom
fix/92-deterministic-solution-pick
Open

matt-edmondson wants to merge 1 commit into
mainfrom
fix/92-deterministic-solution-pick

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #92

What was wrong

Sdk.props took _SolutionFiles.Split(';')[0] from Directory.GetFiles, which guarantees no order. In a directory with several solution files, SolutionName therefore depended on the file system: NTFS lists alphabetically, ext4 by hash. Project-type detection, ToolCommandName and package identity all depend on SolutionName. The issue's repro (Aaa.sln, Foo.sln, Foo.Samples.sln beside Foo.Tool) picked Foo.Samples on Linux, so the tool project stopped being detected as one.

Change

  • Sdk/Sdk.props: with several candidates (.slnx is still preferred over .sln), the solution named after the solution directory wins. Otherwise the ordinally smallest path is used. MSBuild property functions can't sort, so the minimum is unrolled over the first ten candidates (String.CompareOrdinal). That is far more solution files than one directory holds in practice. A solution that set SolutionPath (dotnet build Foo.sln) still wins, as before.
  • Sdk/Sdk.targets: new warning KTSU1006. It fires when the pick was not the directory-named solution and SolutionName wasn't already set. The message tells the user to set SolutionName in Directory.Build.props. It runs once per project: in the outer build, not again in every inner build.
  • README and CLAUDE.md describe the rule.

Tests

New SolutionDiscoveryTests (5 tests):

  • named-after-directory wins, for three creation orders
  • with no match, the ordinally first wins, for three creation orders
  • KTSU1006 is raised
  • no warning when SolutionName is set
  • a single solution behaves as before

With the Sdk.props/Sdk.targets change reverted, all 5 fail. The two behaviour tests fail with exactly the issue's symptom: Expected:<Demo>. Actual:<Demo.Samples> and Expected:<Alpha>. Actual:<Demo>.

Full Sdk.Examples.Tests suite on this branch (Linux): 111 passed, 0 failed.


Generated by Claude Code

… [patch]

Sdk.props took the first entry of Directory.GetFiles, which guarantees no
order, so with several solution files SolutionName - and the project-type
detection, ToolCommandName and package identity keyed on it - depended on
the file system. Prefer the solution named after the solution directory,
otherwise take the ordinally smallest path, and warn KTSU1006 when the pick
was ambiguous and SolutionName was not already set.

Fixes #92

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW5RdbhA7TAMDQD8QTG
@sonarqubecloud

sonarqubecloud Bot commented Nov 4, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants