如果我使用“dotnet new angular”创建项目,我可以在 Visual Studio 2017 中调试 C# 和 Typescript 代码。但在 Visual Studio Code 中,我只能调试 C#。当我尝试在任何 Typescript 指令上放置断点时,它说:“没有为该文档加载任何符号”。由于它在 VS 2017 中运行良好,在我看来,Typescript 配置应该没问题。
当我在 VSCode 中打开项目时,它显示“您的项目缺少构建和调试所需的 Assets 。添加它们?”我回答"is",然后它添加了包含 launch.json 和 tasks.json 的“.vscode”文件夹。也许它没有为调试器添加正确的启动配置? launch.json 中唯一的配置用于“.NET Core Launch (web)”和“.NET Core Attach”。
我安装了 Debugger for Chrome 3.5.0 扩展程序。
这是生成的 launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/netcoreapp2.0/spa.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart",
"launchBrowser": {
"enabled": true,
"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": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
最佳答案
这是 VSCode 生成的 launch.json 文件的问题。我需要为 Chrome 调试器添加一个配置。我还需要添加一个“复合”配置,以便在同一 session 中调试 C# 和 Typescript。以下是所需的额外配置。选择“完整堆栈”配置以调试 C# 和 Typescript。
在 Github 上 Microsoft/vscode-recipes 存储库中的 auchenberg 的帮助下,我找到了解决方案。我创建了一个拉取请求来添加这个新食谱。 (参见:https://github.com/Microsoft/vscode-recipes/tree/master/Angular-SpaTemplates)
所需的额外配置是:
{
"name": ".NET Core Launch (full)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/netcoreapp2.0/spa.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart",
"launchBrowser": {
"enabled": false
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"type": "chrome",
"request": "launch",
"name": "Chrome",
"url": "http://localhost:5000",
"webRoot": "${workspaceRoot}/wwwroot"
}
],
"compounds": [
{
"name": "Full stack",
"configurations": [".NET Core Launch (full)", "Chrome"]
}
]
关于typescript - 在同一 session 中调试 VSCode 中的 Typescript 和 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47598215/