docs/workflow/debugging/libraries/debugging-vscode.md
runtime/src/libraries/System.Net.Socketsctrl-shift-D or click on the button on the left.NET Core from the selection dropdownlaunch.json configuration file make the following changes:
preLaunchTask propertyprogram to the full path to dotnet in the artifacts/bin/testhost directory.
{full path to your dotnet/runtime directory}/artifacts/bin/testhost/net{Version}-{OS}-{Configuration}-{Architecture}/dotnet.cwd to the test bin directory.
{full path to your dotnet/runtime directory}/artifacts/bin/System.Net.Sockets.Tests/Debug/net{Version}-{OS}. Exact naming/structure might differ based on which library you are debugging.args to the command line arguments to pass to the test
[ "exec", "--runtimeconfig", "{TestProjectName}.runtimeconfig.json", "xunit.console.dll", "{TestProjectName}.dll", "-notrait", ... ], where TestProjectName would be System.Net.Sockets.Tests[ "-method", "System.Net.Sockets.Tests.{ClassName}.{TestMethodName}", ...]exec. Copy all arguments and reformat them in launch.json as shown above.
dotnet build /t:Test in runtime/src/libraries/System.Net.Sockets/tests/FunctionalTests has terminal output including "exec --runtimeconfig System.Net.Sockets.Tests.runtimeconfig.json ... -notrait category=failing", which can be reformatted into ["exec","--runtimeconfig","System.Net.Sockets.Tests.runtimeconfigjson", ... ,"-notrait","category=failing"]dotnet build /t:Test /p:xUnitMethodName=System.Net.Sockets.Tests.{ClassName}.{TestMethodName} will get you the args needed to debug a specific test.vscode in the currently open directory, so it's much easier to preserve during git clean -dfx.To debug the libraries on a "desktop" platform (Linux/Mac/Windows, not WebAssembly, or iOS or Android) running on Mono runtime, follow the instructions below. See also Android debugging and WebAssembly debugging.
Install the VS Code Mono Debugger (ms-vscode.mono-debug) extension
Create a launch.json file configuration with type mono
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Mono",
"type": "mono",
"request": "attach",
"address": "localhost",
"port": 1235
}
]
}
start a test from the command line, setting the MONO_ENV_OPTIONS environment variable to configure the debugger:
DOTNET_REMOTEEXECUTOR_SUPPORTED=0 MONO_ENV_OPTIONS="--debug --debugger-agent=transport=dt_socket,address=127.0.0.1:1235,server=y,suspend=y" ./dotnet.sh build /t:Test /p:RuntimeFlavor=Mono src/libraries/System.Buffers/tests
Note that you also have to set DOTNET_REMOTEEXECUTOR_SUPPORTED=0 otherwise multiple instances of the runtime will attempt to listen on the same port.
On Windows, do not pass --debug in MONO_ENV_OPTIONS.
Set a breakpoint in a test in VS Code and start debugging in the "Attach to Mono" configuration.
Note that Mono does not stop on first chance exceptions and xunit catches all exceptions, so if a test is throwing, the debugger won't break on an uncaught exception.