如何在 linux(ubuntu) 中使用 vscode 调试 asp.net 核心 3.1



我按照默认步骤操作

  • install .NET Core, (linux-package-manager-ubuntu-1604(
  • 在 VSCode 中创建并打开(ASP.NET 核心空(项目,(cd ~/projects && dotnet new web -o my-api && cd my-api && code .(
  • add vscode tasks.json and launch.json(C# Extension(, (ms-dotnettools.csharp(
  • 添加断点(在 VSCode 中(,
  • 并开始调试(在 VSCode 中按 F5(。

但这不会启动网络服务器,也不会在断点处停止...... 它确实构建了项目,因为我可以看到在bin/Debug/netcoreapp3.1/中生成的文件。

在项目root中运行dotnet run,构建(恢复(并运行Web服务器,我可以浏览到 https://localhost:5001 和 http://localhost:5000。但无法调试...

这是创建的 vscode 文件

launch.json
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"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/netcoreapp3.1/my-api.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
"action": "openExternally",
"pattern": "^\s*Now listening on:\s+(https?://\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/my-api.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/my-api.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/my-api.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}

F5首先显示Terminal选项卡,然后切换到 VSCode 中的Debug Console

选项卡
Terminal-tab
> Executing task: dotnet build /home/user/projects/my-api/my-api.csproj /property:GenerateFullPaths=true /consoleloggerparameters:NoSummary <
Microsoft (R) Build Engine version 16.5.0+d4cbfca49 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 76,69 ms for /home/user/projects/my-api/my-api.csproj.
my-api -> /home/user/projects/my-api/bin/Debug/netcoreapp3.1/my-api.dll
Terminal will be reused by tasks, press any key to close it.
Debug Console
-------------------------------------------------------------------
You may only use the Microsoft .NET Core Debugger (vsdbg) with
Visual Studio Code, Visual Studio or Visual Studio for Mac software
to help you develop and test your applications.
-------------------------------------------------------------------

这似乎是VS Code本身安装的问题,我只是重新安装了VS Code,问题就消失了。

sudo snap remove code
sudo snap install code --classic

虽然这个解决方案不令人满意,但我有一个假设,为什么会发生这种情况。

我使用 CLI 而不是使用 GUI 安装了模块。我这么说是因为我在运行 Web 应用程序时看到了安装日志。我想调试器的安装可能在我运行应用程序时尚未完成。这可能会导致包损坏。但是,只是卸载扩展程序并不能解决问题,所以我不确定发生了什么。

code --install-extension ms-dotnettools.csharp

如果重新安装对您不起作用,请告诉我,并尝试更改您的launch.json,将openExternally替换为debugWithChrome。我在重新安装VS Code的同时更改了设置。

我遇到了同样的问题。

首先重新启动系统,看看它是否得到修复。 否则,请尝试MathieuAuclair的解决方案,然后重新启动系统。

这对我有用。

相关内容

  • 没有找到相关文章

最新更新