MSB1011: Specify which project or solution file to use because this folder contains
more than one project or solution file. means dotnet build found several
candidates in the current folder and refuses to guess. Name the one you want:
dotnet build FixLab.csproj or dotnet build FixLab.slnx.
If the extra file is a leftover (a renamed copy, a backup, an old solution next to a new
.slnx), move it out of the folder and plain dotnet build works
again. If both files are meant to be there, pass the path every time, in scripts and CI too.
The error
PS> Get-ChildItem *.csproj | Select Name
FixLab.csproj
FixLab.Old.csproj
PS> dotnet build
MSBUILD : error MSB1011: Specify which project or solution file to use because this folder contains more than one project or solution file.
Why it happens
When you run a build command without a project argument, MSBuild looks at the project and solution files in the current folder only. With exactly one, it builds it. With none, you get MSB1003. With two project files, or two solution files, it cannot know which one you meant and stops with MSB1011 before compiling anything.
One project file and one solution file side by side is not ambiguous: MSBuild takes the
solution. In the test below, a folder holding FixLab.csproj and
FixLab.slnx built without complaint, and the error came back as soon as a second
solution file, FixLab.Old.slnx, was copied in. The common real-world causes are
a copied project file kept "just in case", a test project created in the same folder as the
app instead of its own folder, and an old .sln left next to a migrated
.slnx.
The fix
PS> dotnet build FixLab.csproj
Build succeeded.
0 Warning(s)
0 Error(s)
Passing the file name told MSBuild which project to build, and the build succeeded; the path
line of the output is left out. For the two-solution case,
dotnet build FixLab.slnx did the same. Keep in mind that two project files in
one folder also share one obj folder, which can make restores confusing, so the
lasting fix is one project per folder: give each project its own directory and tie them
together with a solution.
How it was reproduced
On Windows 11 with .NET SDK 10.0.401, in Windows PowerShell 5.1: a console project from
dotnet new console -n FixLab (target net10.0), then
Copy-Item FixLab.csproj FixLab.Old.csproj to put a second project file next to
it. dotnet build failed with the message above and
dotnet build FixLab.csproj succeeded. A second folder with
dotnet new sln -n FixLab (the .NET 10 SDK writes an .slnx) and the
project added to it built fine; copying the solution to FixLab.Old.slnx
produced the same MSB1011, and naming FixLab.slnx cleared it. A third folder with
both a FixLab.sln and a FixLab.slnx failed the same way.
Frequently asked
- How do I fix MSB1011 in dotnet build?
- Pass the project or solution file you want as the first argument, for example dotnet build MyApp.csproj or dotnet build MyApp.slnx, or move the extra project or solution file out of the folder.
- Can a .csproj and a .sln be in the same folder?
- Yes. With exactly one project file and one solution file in the folder, dotnet build picks the solution and builds without MSB1011. The error appears with two project files or two solution files.
- Why do I get MSB1011 after migrating to slnx?
- If the old .sln is still next to the new .slnx, the folder holds two solution files and MSBuild will not choose. Delete or move the old .sln once the .slnx builds, or name the file you want.
The opposite case, no project file at all, is MSB1003: Specify a project or solution file. More decoded errors are in the Fixes category.