I've installed .NET Core 2.2 in the Windows Subsystem for Linux (WSL) and created a new project. I've also installed the C# extension for Visual Studio Code and the syntax highlighting and IntelliSense seems to be working.
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 file:
{
// 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 file:
{
// 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
Open the Debug view by selecting the Debugging icon on the left side menu. Select the green arrow at the top of the pane, next to . NET Core Launch (console). Other ways to start the program in debugging mode are by pressing F5 or choosing Run > Start Debugging from the menu.
To bring up the Run and Debug view, select the Run and Debug icon in the Activity Bar on the side of VS Code. You can also use the keyboard shortcut Ctrl+Shift+D. The Run and Debug view displays all information related to running and debugging and has a top bar with debugging commands and configuration settings.
From VS Code You can also access more VS Code WSL options by using the shortcut: CTRL+SHIFT+P in VS Code to bring up the command palette. If you then type WSL you will see a list of the options available, allowing you to reopen the folder in a WSL session, specify which distribution you want to open in, and more.
Debugging in WSL Once you've opened a folder in WSL, you can use VS Code's debugger in the same way you would when running the application locally. For example, if you select a launch configuration in launch. json and start debugging (F5), the application will start on remote host and attach the debugger to it.
There is a great article on GitHub regarding the subject - Windows Subsystem for Linux.
To cut a long story short, you need to first verify your version after the Windows 10 Creators Update:
~$ 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. If the version is 14, run the following commands in a cmd prompt to reinstall and update 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
The debugger will be installed at ~/vsdbg/vsdbg
. It is the debuggerPath.
Sample launch.json configuration for launch:
{
"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):
{
"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. Since coreclr is cross-platform, the binary can be executed on WSL without any extra work.
pipeProgram is set to bash.exe.
debuggerPath points to vsdbg, the coreclr debugger.
This will not support programs that want to read from the console.
Sample launch.json configuration for attach:
{
"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.quoteArgs
will quote any arguments and debugger commands with spaces if set to true.sourceFileMap
to map sources if they are available in a
different location than where they were built. If you build your
project in Linux, make sure to add a map from the /mnt
drive
letters. Example: "sourceFileMap": { "/mnt/c/": "c:\\" }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With