Skip to main content

Fixed: "MSB1011: Specify which project or solution file to use because this folder contains more than one project or solution file."

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

MSBUILD : error MSB1011: Specify which project or solution file to use because this folder contains more than one project or solution file. I got it from a plain dotnet build, seconds after converting a solution to the new .slnx format. The conversion had worked; it had also left two solution files in one folder, and MSBuild won't guess which one you mean.

What I Was Doing​

I had an older solution, Legacy.sln, with one class library, and converted it to the .slnx format that .NET 10 uses by default:

Terminal
dotnet sln Legacy.sln migrate
Output
.slnx file /Users/you/projects/sln-migrate/Legacy.slnx generated.

Then I built, the way I always do, without naming a file:

Terminal
dotnet build

What I Expected​

The same build as before, from the new file.

What I Got​

Output
MSBUILD : error MSB1011: Specify which project or solution file to use because this folder contains more than one project or solution file.

A terminal where dotnet build, in a folder with Legacy.sln and Legacy.slnx, fails with MSBUILD : error MSB1011: Specify which project or solution file to use because this folder contains more than one project or solution file.

Nothing was built.

What I Checked​

What dotnet build looks for. The dotnet build reference: "If a file isn't specified, MSBuild searches the current directory for a project or solution." The folder now held two solution files: Legacy.sln, which migrate leaves in place, and the new Legacy.slnx.

What Microsoft's MSB1011 page says. The error's page describes the search: "If no project or solution file is explicitly specified on the MSBuild.exe command-line, then the engine searches for a project or solution file by looking for *.*proj or *.sln (or *.slnx with MSBuild 17.13 and later)." And one case that is fine: "It's not an error to have a folder with a solution file and a single project file with the same name. In that case, the solution file is used for the build."

The page doesn't describe my case, two solution files in one folder, but the message does: "this folder contains more than one project or solution file". MSBuild found two candidates and stopped instead of picking one.

Why It Happens​

dotnet sln migrate writes the .slnx next to the .sln and leaves the old file in place. When no file is named, MSBuild searches the current folder for a project or solution file; here it found two solution files, and it stopped instead of picking one.

The Fix​

There are two, depending on whether you still need the old file.

Name the file you mean. The page's resolution: "specify either the solution file or the project file explicitly on the command line."

Terminal
dotnet build Legacy.slnx
Output
Restore complete (0.4s)
Legacy.Core net10.0 succeeded (0.2s) → src/Legacy.Core/bin/Debug/net10.0/Legacy.Core.dll

Build succeeded in 0.8s

The same goes for other commands that search the folder: in a folder with two solution files, dotnet restore and dotnet test failed with the same MSB1011 until I named the file.

Or keep one solution file per folder. Once the .slnx works, the .sln has no job left. I renamed it, so it was out of MSBuild's search but still there to compare:

Terminal
mv Legacy.sln Legacy.sln.old
dotnet build

After the Fix​

Output
Restore complete (0.4s)
Legacy.Core net10.0 succeeded (0.1s) → src/Legacy.Core/bin/Debug/net10.0/Legacy.Core.dll

Build succeeded in 0.7s

A terminal where dotnet build Legacy.slnx succeeds, and after renaming Legacy.sln to Legacy.sln.old, a plain dotnet build succeeds too.

Plain dotnet build works again, because the folder has one solution file. In a Git repository, remove the old file in the same commit as the new one (git rm Legacy.sln), so nobody keeps editing the file that the build no longer uses.

Other Folders That Cause MSB1011​

The same error appears whenever the search finds more than one candidate, for example:

  • Several project files in one folder. I copied a .csproj next to itself under another name, and dotnet build in that folder failed with the same MSB1011.
  • A solution and a project with different names in the same folder; Microsoft's page covers exactly this one: "if only one project file is found, and it has a different name than a solution file in the same folder (not counting the file extension), then MSBuild issues this error."

The fix is the same: name the file, or tidy the folder.

Common Mistakes​

MistakeWhat happensDo this instead
Keeping the .sln and .slnx after migratingEvery unnamed dotnet command fails with MSB1011Remove or rename the old file
Naming the .sln in build scripts after migratingScripts build the old file while the IDE uses the new onePoint scripts at the .slnx
Running dotnet sln migrate again to "fix" itThe docs: it fails if an .slnx "with the same file name … already exists in the directory"Migrate once

Troubleshooting​

SymptomLikely causeFix
MSB1011 right after dotnet sln migrateThe .sln and the new .slnx are both in the folderName the file, or rename or remove the .sln
MSB1011 in a folder with several .csproj filesThe search finds more than one projectName the project file, or move the extra one out
MSB1011 with one project and one solution of different namesMicrosoft's page lists this caseName the file you mean
dotnet restore or dotnet test fail with the same messageThey search the folder the same wayName the file for them too

FAQ​

Does Visual Studio care about two solution files?​

Visual Studio opens the one you choose, so it doesn't show this error. It's the command-line search that needs a single candidate, which is why the error appears in terminals and CI builds.

Which file wins if I name a folder instead of a file?​

None. Naming the folder searches it the same way, with a slightly different error. dotnet build . in a folder with two solution files printed:

Output
MSBUILD : error MSB1050: Specify which project or solution file to use because the folder "." contains more than one project or solution file.

Name the file itself.

Conclusion​

MSB1011 means MSBuild found more than one project or solution file in the folder and won't guess. After dotnet sln migrate, that's the old .sln next to the new .slnx. Name the file in the command, dotnet build Legacy.slnx, or keep a single solution file in the folder, and plain dotnet build works again.

Additional Resources​

Stay Updated

Subscribe to our newsletter for the latest tutorials, tech insights, and developer news.

By subscribing, you agree to our privacy policy. Unsubscribe at any time.