[英]How can I configure Visual Studio Code to run/debug .NET (dotnet) Core from the Windows Subsystem for Linux (WSL)?
I've installed dotnet core 2.2 in the Windows Subsystem for Linux (WSL) and created a new project. 我已经在Windows子系统Linux(WSL)中安装了dotnet core 2.2并创建了一个新项目。 I've also installed the C# extension for Visual Studio Code and the syntax highlighting and IntelliSense seems to be working.
我还安装了Visual Studio Code的C#扩展,语法高亮和IntelliSense似乎正在工作。
However, when I try to use the debugger things stop working. 但是,当我尝试使用调试器时,事情就停止了。 Here's a step by step of what I've tried to do to configure it.
这是我尝试配置它的一步一步。
Here's my launch.json: 这是我的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}"
}
]
}
And my tasks.json: 和我的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"
}
]
}
My directory structure: 我的目录结构:
But when I click the "Start Debugging" button I get the following error: 但是当我单击“开始调试”按钮时,我收到以下错误:
launch: program " does not exist
There is a great article on github regarding the subject - Windows Subsystem for Linux . 关于这个主题的github上有一篇很棒的文章 - 适用于Linux的Windows子系统 。
To cut a long story short, you need to first verify your version after windows 10 creators update: 简而言之,您需要在Windows 10创建者更新后首先验证您的版本:
~$ cat /etc/os-release | grep -i version
VERSION="16.04.2 LTS (Xenial Xerus)"
VERSION_ID="16.04"
VERSION_CODENAME=xenial
Notice the following : 请注意以下事项 :
If you had upgraded to Windows Creators update and already had WSL installed, you might still have Ubuntu 14 in the WSL.
如果您已升级到Windows Creators更新并且已经安装了WSL,那么您可能仍然在WSL中安装了Ubuntu 14。 If the version is 14, run the following commands in a cmd prompt to reinstall and update WSL.
如果版本为14,请在cmd提示符中运行以下命令以重新安装和更新WSL。
lxrun /uninstall /full
lxrun /install
Download the debugger : 下载调试器 :
sudo apt-get install unzip
curl -sSL https://aka.ms/getvsdbgsh | bash /dev/stdin -v latest -l ~/vsdbg
Debugger will be installed at ~/vsdbg/vsdbg
, it is the debuggerPath . 调试器将安装在
~/vsdbg/vsdbg
,它是debuggerPath 。
Sample launch.json configuration for launch : 发布示例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"
}
}
Please note: 请注意:
Sample 'publish' task for tasks.json (needed for launching) : tasks.json的示例'publish'任务(启动时需要) :
{
"version": "2.0.0",
"tasks": [
...,
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/wslApp.csproj",
"-o",
"${workspaceFolder}/bin/publish"
]
}
]
}
Please Note : 请注意 :
preLaunchTask executes dotnet publish, which builds the project on Windows. preLaunchTask执行dotnet发布,它在Windows上构建项目。 Since coreclr is cross-platform, the binary can be executed on WSL without any extra work.
由于coreclr是跨平台的,因此二进制文件可以在WSL上执行而无需任何额外的工作。
pipeProgram is set to bash.exe. pipeProgram设置为bash.exe。
debuggerPath points to vsdbg, the coreclr debugger. debuggerPath指向coreclr调试器vsdbg。
This will not support programs that want to read from the console. 这不支持想要从控制台读取的程序。
Sample launch.json configuration for 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
}
}
Please Note : 请注意 :
"processId": "${command:pickRemoteProcess}"
lists the processes running on WSL using the pipe program. "processId": "${command:pickRemoteProcess}"
使用管道程序列出在WSL上运行的进程。 quoteArgs
will quote any arguments and debugger commands with spaces if set to true. quoteArgs
将引用带空格的任何参数和调试器命令。 sourceFileMap
to map sources if they are available in a different location than where they were built. sourceFileMap
来映射源。 If you build your project in Linux, make sure to add a map from the /mnt
drive letters. /mnt
驱动器号添加地图。 Example: "sourceFileMap": { "/mnt/c/": "c:\\\\" }
"sourceFileMap": { "/mnt/c/": "c:\\\\" }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.