MSB1003: Specify a project or solution file. The current working directory does not
contain a project or solution file. means dotnet build looked in the
folder you are standing in and found no .csproj, .sln or
.slnx there. Move into the folder that holds the project, or pass its path to
the command.
Either cd FixLab and run dotnet build again, or stay where you are
and run dotnet build FixLab, which accepts a folder, a project file or a
solution file. dotnet restore and dotnet publish give the same
MSB1003 in an empty folder; dotnet run words it differently (Couldn't
find a project to run) and takes the path through --project.
The error
PS> dotnet --version
10.0.401
PS> cd empty; dotnet build
MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.
Why it happens
The dotnet commands that build something hand their work to MSBuild, and when
you give MSBuild no project argument it looks only in the current working directory. It
does not search parent folders or subfolders. If that one folder holds no project or
solution file, it stops with MSB1003 before anything is compiled.
The usual way to meet it is a terminal that opened one level too high: you cloned a
repository and stayed in its root while the project sits in src/, you created
a project with dotnet new console -o FixLab and forgot that -o
made a new folder, or an editor terminal opened in the workspace root rather than in the
project. A CI step with the wrong working directory gives the same message.
The fix
PS> dotnet build FixLab
Build succeeded.
PS> cd FixLab; dotnet build
Build succeeded.
Both forms built the same project; the output is trimmed to the result lines. Passing the
path is the better habit in scripts and CI, because it does not depend on where the shell
happens to be. In a pipeline, set the step's working directory or give the path to the
.csproj or solution explicitly. If you are not sure where the project is,
Get-ChildItem -Recurse -Filter *.csproj in PowerShell or
find . -name "*.csproj" in a Unix shell lists every project below you.
If the folder holds two or more project or solution files instead of none, MSBuild stops with the opposite message, MSB1011, and the answer there is also to name the file you mean.
How it was reproduced
On Windows 11 with .NET SDK 10.0.401, in Windows PowerShell 5.1: dotnet build
in an empty folder produced the error above. A project was then created inside that folder
with dotnet new console -n FixLab -o FixLab (target net10.0), and
both dotnet build FixLab from the parent folder and
cd FixLab; dotnet build built it with 0 warnings and 0 errors. The full paths
in the build output are left out of the block above; nothing else was changed.
Frequently asked
- What does MSB1003 mean in dotnet build?
- MSBuild found no project or solution file in the current folder and you did not pass one. It only looks in the folder you run the command from, not in subfolders, so cd into the project folder or give the path.
- How do I run dotnet build from a different folder?
- Pass the path as the first argument: dotnet build path/to/MyApp, dotnet build path/to/MyApp.csproj or dotnet build path/to/MyApp.slnx. dotnet restore and dotnet publish take the path the same way; dotnet run takes it with --project.
- Why does dotnet build fail in my CI pipeline with MSB1003?
- The step runs in the repository root while the project lives in a subfolder. Set the step's working directory to the project folder, or pass the project or solution path to dotnet build.
The opposite case is covered in MSB1011: more than one project or solution file. More decoded errors are in the Fixes category.