mirror of
https://github.com/BepInEx/dotnet-runtime.git
synced 2026-11-23 03:39:35 -10:00
2.8 KiB
2.8 KiB
Debugging Libraries with Visual Studio Code
- Install Visual Studio Code
- Install the C# Extension
- Open the folder containing the source you want to debug in VS Code - i.e., if you are debugging a test failure in System.Net.Sockets, open
runtime/src/libraries/System.Net.Sockets - Open the debug window:
ctrl-shift-Dor click on the button on the left - Click "create a launch.json file", select the option that includes
.NET Corefrom the selection dropdown - In the ".NET Core Launch (console)"
launch.jsonconfiguration file make the following changes:- delete the
preLaunchTaskproperty - set
programto the full path todotnetin the artifacts/bin/testhost directory.- something like
{full path to your dotnet/runtime directory}/artifacts/bin/testhost/net{Version}-{OS}-{Configuration}-{Architecture}/dotnet.
- something like
- set
cwdto the test bin directory.- using the System.Net.Sockets example, it should be something like
{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.
- using the System.Net.Sockets example, it should be something like
- set
argsto the command line arguments to pass to the test- something like:
[ "exec", "--runtimeconfig", "{TestProjectName}.runtimeconfig.json", "xunit.console.dll", "{TestProjectName}.dll", "-notrait", ... ], where TestProjectName would beSystem.Net.Sockets.Tests - to run a specific test, you can append something like:
[ "-method", "System.Net.Sockets.Tests.{ClassName}.{TestMethodName}", ...] - to find the exact arguments to replicate a test run you are trying to debug, run the test command in a terminal and look for output starting with
exec. Copy all arguments and reformat them inlaunch.jsonas shown above.- ex. running
dotnet build /t:Testinruntime/src/libraries/System.Net.Sockets/tests/FunctionalTestshas 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"] - similarly, running
dotnet build /t:Test /p:xUnitMethodName=System.Net.Sockets.Tests.{ClassName}.{TestMethodName}will get you the args needed to debug a specific test
- ex. running
- something like:
- delete the
- Set a breakpoint and launch the debugger (running ".NET Core Launch (console)"), inspecting variables and call stacks will now work.
- Optionally, save the launch settings in a workspace file. The advantage is that it doesn't necessarily need to reside in
.vscodein the currently open directory, so it's much easier to preserve duringgit clean -dfx.