Cap*_*ack 10 c# debugging .net-core visual-studio-code windows-subsystem-for-linux
我已经在Windows子系统Linux(WSL)中安装了dotnet core 2.2并创建了一个新项目.我还为Visual Studio Code安装了C#扩展,语法高亮显示和IntelliSense似乎正在工作.
但是,当我尝试使用调试器时,事情就停止了.这是我尝试配置它的一步一步.
这是我的launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/bin/Debug/netcoreapp2.2/CodeCore.dll",
"args": [],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/bin/Debug/netcoreapp2.2/CodeCore.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}"
}
]
}
Run Code Online (Sandbox Code Playgroud)
和我的tasks.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet build",
"type": "shell",
"group": "build",
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我的目录结构:
但是当我单击"开始调试"按钮时,我收到以下错误:
launch: program " does not exist
Run Code Online (Sandbox Code Playgroud)
GitHub 上有一篇关于该主题的精彩文章 -适用于 Linux 的 Windows 子系统。
长话短说,您需要在 Windows 10创意者更新之后首先验证您的版本:
~$ cat /etc/os-release | grep -i version
VERSION="16.04.2 LTS (Xenial Xerus)"
VERSION_ID="16.04"
VERSION_CODENAME=xenial
Run Code Online (Sandbox Code Playgroud)
请注意以下几点:
如果您已升级到 Windows Creators 更新并且已经安装了 WSL,则 WSL 中可能仍然有 Ubuntu 14。如果版本为 14,请在 cmd 提示符下运行以下命令以重新安装和更新 WSL。
lxrun /uninstall /full
lxrun /install
Run Code Online (Sandbox Code Playgroud)
下载调试器:
~$ cat /etc/os-release | grep -i version
VERSION="16.04.2 LTS (Xenial Xerus)"
VERSION_ID="16.04"
VERSION_CODENAME=xenial
Run Code Online (Sandbox Code Playgroud)
调试器将安装在~/vsdbg/vsdbg. 它是debuggerPath。
用于启动的示例 launch.json 配置:
{
"name": ".NET Core WSL Launch",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "publish",
"program": "/mnt/c/temp/dotnetapps/wslApp/bin/publish/wslApp.dll",
"args": [],
"cwd": "/mnt/c/temp/dotnetapps/wslApp",
"stopAtEntry": false,
"console": "internalConsole",
"pipeTransport": {
"pipeCwd": "${workspaceRoot}",
"pipeProgram": "bash.exe",
"pipeArgs": [ "-c" ],
"debuggerPath": "~/vsdbg/vsdbg"
}
}
Run Code Online (Sandbox Code Playgroud)
请注意:
tasks.json 的 示例“发布”任务(启动所需):
{
"version": "2.0.0",
"tasks": [
...,
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/wslApp.csproj",
"-o",
"${workspaceFolder}/bin/publish"
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
请注意:
preLaunchTask 执行dotnet publish,它在 Windows 上构建项目。由于 coreclr 是跨平台的,二进制文件可以在 WSL 上执行而无需任何额外工作。
pipeProgram 设置为bash.exe。
debuggerPath 指向 vsdbg,coreclr 调试器。
这将不支持想要从控制台读取的程序。
attach 的示例 launch.json 配置:
{
"name": ".NET Core WSL Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickRemoteProcess}",
"pipeTransport": {
"pipeCwd": "${workspaceRoot}",
"pipeProgram": "bash.exe",
"pipeArgs": [ "-c" ],
"debuggerPath": "~/vsdbg/vsdbg",
"quoteArgs": true
}
}
Run Code Online (Sandbox Code Playgroud)
请注意:
"processId": "${command:pickRemoteProcess}" 使用管道程序列出在 WSL 上运行的进程。quoteArgs 如果设置为 true,将引用带空格的任何参数和调试器命令。sourceFileMap,如果他们在不同的位置比他们建在哪里都可以映射来源。如果您在 Linux 中构建项目,请确保从/mnt驱动器号添加映射。例子:"sourceFileMap": { "/mnt/c/": "c:\\" }| 归档时间: |
|
| 查看次数: |
3490 次 |
| 最近记录: |