When running the following command to build a single project:
…the .NET SDK unexpectedly searches and builds other .csproj files within the directory tree—even though no explicit project references exist in project.csproj.
Only project.csproj should be built, as it has no project reference to any of the other .csproj files.
All .csproj files are being discovered and built.
When running dotnet build inside a folder that contains a solution file (.sln), the build may behave differently based on project references and global.json settings.
If you run dotnet build inside a directory with multiple project files, the build system might attempt a restore across all discovered .csproj files (depending on SDK version and MSBuild behavior).
If there’s a solution file (*.sln) in the folder, and it references those projects, then dotnet build may implicitly build all projects listed in that solution file—even if a specific .csproj is passed.
To restrict the build only to the explicitly passed .csproj file:
Ensure you’re not accidentally building a .sln file instead of .csproj. Avoid:
Use:
Sometimes MSBuild gives more fine-grained control:
The /p:BuildProjectReferences=false option prevents MSBuild from following project references (even if defined).
As a fallback:
Work with our skilled .Net developers to accelerate your project and boost its performance.
Copyright © 2025 Niotechone Software Solution Pvt. Ltd. All Rights Reserved.