无法找到&project; json'在当前目录中 - .NET Core Webapp调试

时间:2016-05-25 11:35:04

标签: asp.net-core asp.net-core-mvc visual-studio-code

我尝试使用.NET Core RC2和Visual Studio Code在OSX环境中设置调试。尝试运行调试器时会出现以下错误。

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

目前我已经设置了launch.json(见下文),并在Visual Studio Code中选择了.NET Core Launch(web)。 由于我的项目位于一个名为Core的文件夹中,并与另外两个文件夹共享空间,我的结构看起来像这样。

结构
- vscode
------ launch.json
------ tasks.json

- 核心

- 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>"
    }
]
}

文件夹结构

enter image description here

4 个答案:

答案 0 :(得分:15)

我需要添加此代码

<强> tasks.json

 "options":{
    "cwd": "${workspaceRoot}/Core"
 }

答案 1 :(得分:4)

没有一个答案对我有帮助。我刚刚指定了project.json的整个路径,它开始工作正常。

<强> tasks.json

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

所以,对于这个特殊的问题,它将是

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

答案 2 :(得分:0)

我也遇到了这个问题。我能够通过在应用程序的入口点中指定WebHostBuilder的内容根来修复它。确保您的入口点方法如下所示:

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

    host.Run();
}

该代码的重要部分是:

.UseContentRoot(Directory.GetCurrentDirectory())

这告诉主机在哪里可以找到您的站点资产,包括project.json和您的MVC视图。

答案 3 :(得分:0)

在Ubuntu 16.10上,我进入tasks.json文件并将\\更改为单/属性中的args,如下所示:

"${workspaceRoot}\\project.json"

"${workspaceRoot}/project.json"

之后它完美无缺。下面是我的整个tasks.json(来自dotnet核心入门项目)

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