🛠️ The Startup Project That Wouldn’t Stay Set
Setting a specific project as the startup project in a multi-project solution (right-click > Set as Startup Project) feels like a permanent, solution-level choice – but in solutions using newer, SDK-style project formats, that setting is stored in the .sln file itself, and certain workflows (switching git branches to one with a different .sln, or a solution filter file being used instead of the main solution) can silently revert it back to whatever’s written in whichever solution file actually gets loaded, with no obvious indication of why the ‘wrong’ project suddenly starts running again.
🔎 The Problem
Solution: MyApp.sln, containing MyApp.Api, MyApp.Worker, and MyApp.Tests projects. Developer sets MyApp.Api as the startup project explicitly through Visual Studio'"'"'s UI - this writes the choice into MyApp.sln itself. Later, git checkout switches to a different branch where MyApp.sln was regenerated by a scaffolding tool, or a .slnf (solution filter) file is opened instead of the full .sln for a faster, filtered view of only some projects - either way, a DIFFERENT startup project setting (whatever that specific file happens to specify, often just the first project alphabetically) is what actually loads, silently overriding the explicit choice made moments earlier in the original .sln.
✅ Fix: Know Which Solution File Actually Owns the Setting Being Used
- Checking whether a .slnf (solution filter) file is what’s actually open, rather than the main .sln, is the first thing worth confirming – a solution filter has its own independent startup project setting, and changing it in the UI while the filter is open updates the filter’s own file, not the main solution’s.
- For a startup project choice that genuinely needs to survive branch switches and stay consistent for the whole team, committing the .sln file’s startup-project setting explicitly (rather than leaving it as a personal, undocumented preference each developer sets locally) keeps everyone’s environment consistent without each person needing to reset it individually.
- Multiple startup projects (Solution Properties > Configuration Properties > Startup Project > Multiple startup projects) is worth considering directly for a solution where more than one project genuinely needs to run together during debugging (an API and a background worker, say) – it sidesteps the single ‘set as startup project’ setting reverting unexpectedly by making the multi-project configuration itself the persisted, deliberate choice.
⚠️ Why This Is Confusing Without Realizing Which File Is in Play
- Visual Studio’s UI for setting the startup project looks and behaves identically regardless of whether a .sln or a .slnf is currently open – there’s no obvious visual cue in the moment that the change being made is going into a different file than expected, which is exactly why the setting can seem to ‘randomly’ revert on a later reopen.
- This is particularly common on teams that use solution filters specifically to speed up loading a large solution by excluding unrelated projects – exactly the workflow most likely to have a developer regularly switching between the full .sln and one or more .slnf files without necessarily tracking which one is currently open at any given moment.
The startup project setting isn’t reverting on its own – it’s being read from whichever solution file happens to be open, and a .sln and a .slnf are perfectly happy to disagree about it forever.
