首页 文章

当前目录中的't find ' project.json' - .NET Core Webapp调试

提问于
浏览
9

我正在尝试使用.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的文件夹中,并与另外两个文件夹共享空间,因此我的结构如下所示 .

Structure

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

Folder structure

enter image description here

4 回答

  • 0

    我需要添加此代码

    tasks.json

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

    没有一个答案对我有帮助 . 我刚刚指定了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"
        ],
    
  • 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视图 .

  • 4

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

相关问题