10

I'm trying to setup debugging on OSX environment using .NET Core RC2 and Visual Studio Code. The following error is given when trying to run the debugger.

Couldn't find 'project.json' in current directory

Currently I've setup launch.json (see below) and chosen .NET Core Launch (web) in Visual Studio Code. As my project is in a folder called Core and sharing space with two other folders my structure looks like this.

Structure
--.vscode
------ launch.json
------ tasks.json

-- Core

-- Core.Data

-- Core.Service

launch.json

{
"version": "0.2.0",
"configurations": [
    {
        "name": ".NET Core Launch (console)",
        "type": "coreclr",
        "request": "launch",
        "preLaunchTask": "build",
        "program": "${workspaceRoot}/Core/bin/Debug/netcoreapp1.0/Core.dll",
        "args": [],
        "cwd": "${workspaceRoot}/Core",
        "stopAtEntry": false
    },
    {
        "name": ".NET Core Launch (web)",
        "type": "coreclr",
        "request": "launch",
        "preLaunchTask": "build",
        "program": "${workspaceRoot}/Core/bin/Debug/netcoreapp1.0/Core.dll",
        "args": [],
        "cwd": "${workspaceRoot}/Core",
        "stopAtEntry": false,
        "launchBrowser": {
            "enabled": true,
            "args": "${auto-detect-url}",
            "windows": {
                "command": "cmd.exe",
                "args": "/C start ${auto-detect-url}"
            },
            "osx": {
                "command": "open",
                "args": "-a chrome ${auto-detect-url}"
            },
            "linux": {
                "command": "xdg-open"
            }
        }
    },
    {
        "name": ".NET Core Attach",
        "type": "coreclr",
        "request": "attach",
        "processName": "<example>"
    }
]
}

Folder structure

enter image description here

5
  • Maybe a silly question but do you have a project.json defined in the root of your application?
    – James P
    May 25, 2016 at 12:50
  • @JamesP Not a silly question. :) The project.json is in a folder called Core which means project.json isn't directly in root of /src folder. It seems it looks for it there and that causes the problem. What I don't understand is how configure it to src/Core/project.json?
    – Rovdjuret
    May 25, 2016 at 13:01
  • Do you have global.json in the root, with something like "projects": [ "src", "test" ] in it ?
    – Dmitry
    May 25, 2016 at 14:39
  • @Dmitry Yes I do, exactly like you wrote.. Should I configure it? How?
    – Rovdjuret
    May 25, 2016 at 15:09
  • Try this content: { "projects": [ "src" ], "sdk": { "version": "1.0.0-preview1-002702" } } . This file is required by Azure and by VS2015. Not sure about VS Code, but give it a try.
    – Dmitry
    May 26, 2016 at 11:03

4 Answers 4

15

I needed to add this code

tasks.json

 "options":{
    "cwd": "${workspaceRoot}/Core"
 }
3
  • 7
    This answer turned up in the low quality review queue, presumably because you don't provide any explanation of the code. If this code answers the question, consider adding adding some text explaining the code in your answer. This way, you are far more likely to get more upvotes — and help the questioner learn something new.
    – lmo
    Jun 26, 2016 at 19:20
  • 1
    This fixed my issue too. I wanted to be able to open the root solution folder and have it run WebApi. Adding the options mentioned above in the root of the tasks.json tells Code to run from the WebApi and use it's project.json.
    – Kizmar
    Jul 5, 2016 at 13:10
  • this worked for me too. This indicates the current working directory of the executed command or script (as the vscode shows) and defaults to ${workspaceRoot}. I'm not sure how the marked solution worked for other people, because without this value setup properly the project was not even building.
    – adglopez
    Jul 9, 2016 at 13:40
4

None of the answers helped me. I just specified the whole path to project.json and it began to work fine.

tasks.json

{
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
    {
        "taskName": "build",
        "args": [
            "${workspaceRoot}\\project.json"
        ],
        "isBuildCommand": true,
        "problemMatcher": "$msCompile"
    }
]}

So, for this particular question it would be

"args": [
        "${workspaceRoot}\\Core\\project.json"
    ],
0

I ran into this problem as well. I was able to fix it by specifying the content root for the WebHostBuilder in the entry point for the application. Make sure your entry point method looks something like this:

public static void Main(string[] args)
{
    var host = new WebHostBuilder()
        .UseKestrel()
        .UseContentRoot(Directory.GetCurrentDirectory())
        .UseIISIntegration()
        .UseStartup<Startup>()
        .Build();

    host.Run();
}

The important part of that code is:

.UseContentRoot(Directory.GetCurrentDirectory())

This tells the host where to find your site assets, including project.json and your MVC views.

0
0

On Ubuntu 16.10, I went into the tasks.json file and changed the \\ to / in the single args property like below:

"${workspaceRoot}\\project.json"

to

"${workspaceRoot}/project.json"

After that it worked flawlessly. Below is my entire tasks.json (it is from a dotnet core starter project)

{
    "version": "0.1.0",
    "command": "dotnet",
    "isShellCommand": true,
    "args": [],
    "tasks": [
        {
            "taskName": "build",
            "args": [
                "${workspaceRoot}/project.json"
            ],
            "isBuildCommand": true,
            "problemMatcher": "$msCompile"
        }
    ]
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.