Skip to content

Discover solution file explicitly in Stage 2 (Windows)#316

Closed
Chris-Wolfgang wants to merge 1 commit into
mainfrom
fix/stage2-solution-discovery
Closed

Discover solution file explicitly in Stage 2 (Windows)#316
Chris-Wolfgang wants to merge 1 commit into
mainfrom
fix/stage2-solution-discovery

Conversation

@Chris-Wolfgang

Copy link
Copy Markdown
Owner

Summary

Replaces bare dotnet restore / dotnet build --no-restore in Stage 2 with explicit solution discovery via git ls-files. Fixes failures across two related symptoms.

Problem

Stage 2's restore/build steps run from the repo root with no solution argument. dotnet then has to guess what to build, which fails in two real scenarios:

Symptom Affected repo example Reason
MSB1003: Specify a project or solution file console-app-template Solution lives in a subfolder (src/ConsoleAppTemplate.sln); repo root has nothing
MSB1011: Specify which project or solution file to use IEquatable-Extensions Two solution files at root (IEquatable Extensions.slnx + Solution.slnx)

Fix

Discover the solution file before running dotnet:

sln=$(git ls-files '*.slnx' | head -1)
[ -z "$sln" ] && sln=$(git ls-files '*.sln' | head -1)
if [ -n "$sln" ]; then
  dotnet restore "$sln"
else
  echo "ℹ️  No solution file found — falling back to bare 'dotnet restore'."
  dotnet restore
fi

Preference order:

  • .slnx (newer XML-based format) before .sln
  • Among multiple candidates of the same extension: alphabetically-first via head -1 (git emits in sorted order, so this naturally prefers root-level over nested when extensions match)
  • Fall back to bare dotnet restore only if no solution exists at all (the build still has to fail loudly in that case — there is no sensible default)

Same logic in both Restore dependencies and Build solution steps.

shell: bash is set explicitly because Windows runners default to pwsh, but bash quoting around space-containing solution names (e.g. IEquatable Extensions.slnx) is more reliable.

Subsumes

IEquatable-Extensions #61 — the per-repo fix for MSB1011. Once this template change propagates, that PR can be closed.

Test plan

  • Verify Stage 2 passes on a normal repo with a single root-level .slnx
  • Verify Stage 2 passes on console-app-template (nested solution)
  • Verify Stage 2 passes on IEquatable-Extensions (multiple solutions)

🤖 Generated with Claude Code

Bare 'dotnet restore' / 'dotnet build --no-restore' in Stage 2 ran
from the repo root and failed in two scenarios:

1. MSB1003 ("Specify a project or solution file") — repos whose
   solution lives in a subfolder (e.g. console-app-template's
   src/ConsoleAppTemplate.sln). The repo root has no solution and
   dotnet refuses to guess.

2. MSB1011 ("Specify which project or solution file to use") — repos
   with multiple solution files at root (e.g. IEquatable-Extensions
   has both 'IEquatable Extensions.slnx' and 'Solution.slnx').

Replace the bare commands with explicit solution discovery via
'git ls-files'. Preference order: .slnx (newer XML-based format)
first, then .sln. Among multiple candidates of the same extension,
pick the alphabetically-first via 'head -1' — git ls-files emits in
sorted order, so this naturally prefers root-level over nested
where extensions match.

Falls back to bare 'dotnet restore' if no solution file exists at
all (the build still has to fail loudly in that case — there is no
sensible default).

This subsumes the per-repo fix in Chris-Wolfgang/IEquatable-Extensions#61
which can be closed once this lands and propagates.
@Chris-Wolfgang Chris-Wolfgang deleted the fix/stage2-solution-discovery branch April 27, 2026 02:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant