MSB1011 when dotnet build or publish runs inside a Docker build
MSB1011Short answer
dotnet build and dotnet publish pick a project by searching the current folder. If a COPY step puts more than one project or solution file in that folder, MSBuild cannot choose. Name the exact .csproj or .sln file in the command, or change WORKDIR to the folder with a single project.
Fix it fast
1Find out which cause you have
Print the project and solution files in the folder where the failing RUN step runs. Add a temporary RUN ls line before it, or check the folder on disk.
RUN pwd && ls -1 *.sln *.slnx *.csproj2Match what you see, then jump to its fix
- 1
dotnet build or dotnet publish is written without a project or solution pathThe command has no file argument and the folder holds severalFix - 2
The Dockerfile copies the entire repo into /src and runs dotnet thereCOPY . . and WORKDIR put the whole repository in one folderFix - 3
The folder has MyApp.sln and MyApp.slnxBoth .sln and .slnx exist for the same solutionFix
- 1
What does the error look like?
MSB1011dotnet build or dotnet publish fails in a RUN step of the Dockerfilethe same command works on your machine inside the project folder
Cause 1 of 3
The command has no file argument and the folder holds several
1Check
Without a file, MSBuild searches the current directory for a project or solution. A folder with a .sln and a .csproj, or with several projects, has no single answer. A .sln and a .slnx of the same solution also count as two.
ls -1 *.sln *.slnx *.csproj2Fix
Pass the one file you want to build.
RUN dotnet restore MyApp.sln
RUN dotnet publish src/MyApp.Web/MyApp.Web.csproj -c Release -o /app/publish3Verify
Rebuild the image.
docker build -t my-app .Confirmed by learn.microsoft.com
Cause 2 of 3
COPY . . and WORKDIR put the whole repository in one folder
1Check
A repository root usually holds a solution file next to project folders, and sometimes a second project file. After COPY . . the working directory is the repository root, so a bare dotnet command sees every file at that level.
ls -1 *.sln *.csproj2Fix
Move into the project folder before the command, or give the project path. Use the path form so it works from the repository root.
WORKDIR /src
COPY . .
WORKDIR /src/src/MyApp.Web
RUN dotnet publish -c Release -o /app/publish3Verify
The publish step prints the output folder and the build finishes.
docker build --progress=plain -t my-app .Confirmed by learn.microsoft.com
Cause 3 of 3
Both .sln and .slnx exist for the same solution
1Check
MSBuild documents that when both formats of a solution are present in one folder, you must name one of them.
ls -1 *.sln *.slnx2Fix
Name the one you use in the command, or delete the one you do not use from the repository.
RUN dotnet build MyApp.slnx -c Release3Verify
Rebuild the image.
docker build -t my-app .Confirmed by learn.microsoft.com
How do I stop it coming back?
- Always give dotnet build, restore and publish an explicit project or solution path in Dockerfiles.
- Do not use -o with a solution path; the SDK documents that it is not allowed for solutions. Publish a single project instead.
- Keep one solution format in the repository.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
- RaheebA consumer app shipped to both stores from one Flutter codebase on a .NET and Azure back end.
Related fixes
Servers
A containerized ASP.NET Core app says the framework Microsoft.AspNetCore.App was not found
Framework: 'Microsoft.AspNetCore.App', version '6.0.0' (x64)
The app asks for a shared framework the final image does not have.
3 causes, each with a fixServers
docker build cannot find a local file or log in to a private NuGet feed
The parameter is incorrect
A Docker build sees only the build context, minus anything in .dockerignore, so files outside it are not found.
4 causes, each with a fixServers
ASP.NET Core container does not answer on the published port
The container is running and logs no error, but the mapped host port never answers
Since .NET 8 the ASP.NET Core container images listen on port 8080, not 80.
3 causes, each with a fixServers
docker build fails with CS5001, no entry point found
error CS0017: Program has more than one entry point defined.
CS5001 means the compiler built an executable project and found no entry point.
4 causes, each with a fixServers
dotnet says it cannot find any installed .NET SDKs (in Docker or on a server)
A compatible .NET SDK was not found
The dotnet command found a runtime but no SDK that fits.
3 causes, each with a fixServers
A .NET app throws culture errors inside a Docker container
en-us is an invalid culture identifier.
Some container images, including Alpine runtime images, ship without ICU, so .NET starts in globalization-invariant mode.
3 causes, each with a fix