/errors/dotnet-cli/couldnt-find-a-project-to-run
dotnet run: Couldn't find a project to run
- tool
- .NET CLI
- exit code
- 1
- versions
- .NET 6 – 10
- os
- any
Couldn't find a project to run. Ensure a project exists in <dir>, or pass the path to the project using --project. means dotnet run found no project file (.csproj, .fsproj or .vbproj) in the current folder. dotnet run only looks in the current folder, and it cannot run a .sln solution. Run it from the project folder or pass --project.
Reproduce it
export DOTNET_NOLOGO=1 DOTNET_CLI_TELEMETRY_OPTOUT=1
dotnet run
echo "exit status: $?"Output
Couldn't find a project to run. Ensure a project exists in /tmp/work, or pass the path to the project using --project. exit status: 1
Fix: point at the project
export DOTNET_NOLOGO=1 DOTNET_CLI_TELEMETRY_OPTOUT=1
dotnet new console -o src/App >/dev/null 2>&1
dotnet run --project src/AppOutput
Hello, World!
--project accepts the project file or the folder that contains it.
Solution folders and folders with two projects
A solution file next to the projects does not help dotnet run, and two project files in one folder produce a different error:
export DOTNET_NOLOGO=1 DOTNET_CLI_TELEMETRY_OPTOUT=1
dotnet new console -o App >/dev/null 2>&1
dotnet new sln -n Demo >/dev/null 2>&1
dotnet run
echo "exit status: $?"
cp App/App.csproj App/Other.csproj
dotnet run --project App
echo "exit status: $?"Output
Couldn't find a project to run. Ensure a project exists in /tmp/work, or pass the path to the project using --project. exit status: 1 Specify which project file to use because App contains more than one project file. exit status: 1
The first run fails because the current folder holds only the solution. The second fails because App now has two project files and --project App does not say which one; pass --project App/App.csproj instead.
How to recognise the cause
List the current folder (ls or dir) and look at the extensions:
| What the folder contains | What to do |
|---|---|
| A .sln or .slnx file and subfolders | Pass the app project, dotnet run --project src/App |
| Nothing project-related (repository root, home folder) | cd into the project folder, or use --project with its path |
| One .csproj that is a class library or test project | Run the executable project instead; libraries cannot be started |
| Several project files | Name one with --project path/to/App.csproj |
The error message itself names the folder dotnet searched (Ensure a project exists in ...), which quickly shows a script or IDE task running from the wrong working directory.
Prevention
In scripts, CI pipelines and README instructions, always use dotnet run --project path/to/App.csproj so the command works from any folder. In a repository with a solution, keep one project per folder; that keeps dotnet run, dotnet build and IDE tooling unambiguous.
Related messages
| Message | Cause |
|---|---|
| Couldn't find a project to run. | No project file in the current folder |
| Specify which project file to use because this folder contains more than one project file. | Several project files in one folder; use --project |
| MSB1003: Specify a project or solution file. | Same situation for dotnet build: no project or solution in the folder |
FAQ
Can dotnet run run a whole solution?
No. A solution groups several projects and does not say which one is the program, so dotnet run needs a single project. dotnet build and dotnet test do accept a solution file.
Which project should I pass in a solution with several projects?
The executable one: its project file has OutputType Exe (console apps) or uses the Web SDK (ASP.NET Core apps). Class libraries and test projects cannot be started with dotnet run.
Does --project need the .csproj file name?
No. --project accepts either the path to the project file or the folder that contains it, as long as that folder holds exactly one project file.