skip to Main Content

How to fix ‘Unable the find the project that contains {path}’ when running c# code in VScode.

I have recently created a new c# project using

dotnet new console

But when running using the run button in the top left, I get a warning message saying
‘Unable to find the project that contains {file path}’ , source: c# Dev Kit

I am able to run programs created more than 2 days ago, but I cannot create new ones.

Using dotnet run works, and the program runs as intended but neither running with the run button works nor automatic error highlighting.

2

Answers


  1. Did you create launch.json and tasks.json files?

    launch.json is used to launch an app for debugging. E.g

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": ".NET Core Launch (web)",
                "type": "coreclr",
                "request": "launch",
                "preLaunchTask": "build",
                "program": "${workspaceFolder}/YourConsoleApp/bin/Debug/net8.0/YourConsoleApp.dll",
                "args": [],
                "cwd": "${workspaceFolder}",
                "stopAtEntry": false,
                "serverReadyAction": {
                    "action": "openExternally",
                    "pattern": "\bNow listening on:\s+(https?://\S+)"
                },
                "env": {
                    "ASPNETCORE_ENVIRONMENT": "Development"
                },
                "sourceFileMap": {
                    "/Views": "${workspaceFolder}/Views"
                }
            },
            {
                "name": ".NET Core Attach",
                "type": "coreclr",
                "request": "attach"
            }
        ]
    }
    

    tasks.json is used to configure scripts and start processes. E.g

    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "build",
                "command": "dotnet",
                "type": "process",
                "args": [
                    "build",
                    "${workspaceFolder}/YourConsoleApp/YourConsoleApp.csproj",
                    "/property:GenerateFullPaths=true",
                    "/consoleloggerparameters:NoSummary"
                ],
                "problemMatcher": "$msCompile"
            },
            {
                "label": "publish",
                "command": "dotnet",
                "type": "process",
                "args": [
                    "publish",
                    "${workspaceFolder}/YourConsoleApp/YourConsoleApp.csproj",
                    "/property:GenerateFullPaths=true",
                    "/consoleloggerparameters:NoSummary"
                ],
                "problemMatcher": "$msCompile"
            },
            {
                "label": "watch",
                "command": "dotnet",
                "type": "process",
                "args": [
                    "watch",
                    "run",
                    "${workspaceFolder}/YourConsoleApp/YourConsoleApp.csproj",
                    "/property:GenerateFullPaths=true",
                    "/consoleloggerparameters:NoSummary"
                ],
                "problemMatcher": "$msCompile"
            }
        ]
    }
    

    You can also take a look here

    https://code.visualstudio.com/docs/editor/debugging

    https://code.visualstudio.com/docs/csharp/debugging

    Login or Signup to reply.
  2. FWIW, when running into this same error in VS Code on Windows, it turned out that I had the wrong version of the .NET SDK installed. You might try getting the latest update for that and see if it resolves the issue.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search