debugging - 使用 ASP.Net Core 在 VSCode 中调试 Typescript

标签 debugging typescript webpack asp.net-core visual-studio-code

此时我正在尝试创建一个基于 ASP.Net Core (C#) 的 React Web 应用程序。我用 TypeScript 编写代码。我将我的代码与 Webpack 捆绑在一起。源映射已启用。

现在我想在 Visual Studio Code 中调试我的 (Typescript) 代码。在 Chrome 中调试效果很好。所以 Source Maps 都工作正常。

这可能吗?在使用 Node.js 服务器时,我发现了很多东西/教程,但在使用 ASP.Net Core 时却一无所获。

感谢您为我指明正确的方向。或者更好的是,写一个小教程来说明我必须如何设置我的 VSCode(launch.json 等)

最佳答案

好的,在又搜索了 3 个小时的网络并关注 GitHub 问题后,我找到了解决方案。

正如@ulubeyn 提到的,您将需要扩展 Chrome 调试器 Link to Debugger for Chrome

然后您必须在 launch.json 中添加一个配置。像这样:

{
    "name": "Launch Chrome",
    "type": "chrome",
    "request": "launch",
    "url": "http://localhost:5000",
    "webRoot": "${workspaceRoot}/wwwroot"
}

自去年 11 月以来,我们能够在 VS Code 中启动多个调试器。为此,您必须添加 "compounds" (source) launch.json 部分,您在其中提到了您想要一起启动的不同配置名称。

这是我的最终 launch.json。请注意,我已在 .NET Core Launch(web )" 配置以防止此配置打开新的浏览器选项卡,因为我们打开了一个新的 Broser,并在 "Launch Chrome" 配置中附加了调试器。

{
 "version": "0.2.0",
 "compounds": [
    {
        "name": "ASP.Net Core & Browser",
        "configurations": [".NET Core Launch (web)", "Launch Chrome"]
    }
 ],
 "configurations": [
    {
        "name": ".NET Core Attach",
        "type": "coreclr",
        "request": "attach",
        "processId": "${command:pickProcess}"
    },
    {
        "name": ".NET Core Launch (web)",
        "type": "coreclr",
        "request": "launch",
        "preLaunchTask": "build",
        "program": "${workspaceRoot}/bin/Debug/netcoreapp1.1/VoteExample.dll",
        "args": [],
        "cwd": "${workspaceRoot}",
        "stopAtEntry": false,
        "launchBrowser": {
            "enabled": false,
            "args": "${auto-detect-url}",
            "windows": {
                "command": "cmd.exe",
                "args": "/C start ${auto-detect-url}"
            },
            "osx": {
                "command": "open"
            },
            "linux": {
                "command": "xdg-open"
            }
        },
        "env": {
            "ASPNETCORE_ENVIRONMENT": "Development"
        },
        "sourceFileMap": {
            "/Views": "${workspaceRoot}/Views"
        }
    },
    {
        "name": "Launch Chrome",
        "type": "chrome",
        "request": "launch",
        "url": "http://localhost:5000",
        "webRoot": "${workspaceRoot}/wwwroot"
    }
 ]
}

现在我们可以在一个 Visual Studio Code 窗口中同时调试 ASP.NET Core 应用程序和客户端代码。 ".NET Core Attach" 配置部分不是必需的,但有时我想将调试器附加到正在运行的进程上。

关于debugging - 使用 ASP.Net Core 在 VSCode 中调试 Typescript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43628397/

相关文章:

node.js - 如何在 WebStorm 中使用 TypeScript 调试用 Node.js 编写的后端

angular - 如何正确地将 3 种类型的 http 请求顺序且动态地链接在一起?

debugging - Visual Studio 2013 调试键盘快捷键不起作用

angular - TypeScript 中的哈希集

typescript - 如何在类型包装器(映射类型)中转发(众所周知的)符号?

typescript - 带有 types.json 的 Webpack

jquery - Laravel Elixir 与 JQuery 和 JQuery UI

Webpack - 错误 : Cannot find module 'node:assert'

java - MediaRecorder 启动Android 7.1.1 模拟器失败

visual-studio - Visual Studio 2015中的经典ASP “Application debugging is disabled”