dotnet sln: Manage Projects in a Solution
dotnet sln adds, removes, or lists the projects referenced by a solution file.
When CI scripts generate or maintain a solution, dotnet sln is how they wire projects in without hand-editing the .sln.
What it does
dotnet sln operates on a .sln file: add registers a project, remove unregisters it, and list prints every project the solution contains. It edits the solution text for you so you do not hand-craft GUIDs and project blocks.
Common usage
dotnet sln list
dotnet sln add src/Api/Api.csproj
dotnet sln MySolution.sln add src/**/*.csproj
dotnet sln remove src/Old/Old.csprojOptions
| Command | What it does |
|---|---|
| list | List projects in the solution |
| add <project> | Add a project to the solution |
| remove <project> | Remove a project from the solution |
| --solution-folder <name> | Place the added project under a solution folder |
| <solution> | Target a specific .sln if more than one exists |
In CI
Use dotnet sln add in scaffolding scripts so generated projects are part of the build. When more than one .sln exists, name the file explicitly or the command errors. dotnet build/test on the solution then covers every registered project, which is cleaner than building each csproj.
Common errors in CI
"Found more than one solution file ... Specify which one to use" means you must pass the .sln path. "Project reference ... does not exist" or "Could not find project" means the project path is wrong relative to the solution. Adding a project that is already in the solution prints "already contains" and is a no-op, not a failure.