【问题标题】:How to debug dotnet core source code using Visual Studio Code如何使用 Visual Studio Code 调试 dotnet core 源代码
【发布时间】:2022-10-16 17:18:20
【问题描述】:

例如,我想在调试我的应用程序时探索 dotnet 的源代码。我想在Where Linq 方法上点击F11,并逐步查看运行时发生的情况。

我知道使用 Visual Studio (https://github.com/dotnet/core/issues/897) 可以做到这一点,并且在 Rider 中默认启用它,并且进入它就像调试我自己的代码一样简单。

在 Visual Studio 代码中设置它的最简单方法是什么,甚至可能吗?

请注意,这不是 Is there anyway to debugging .NET Core source code by Visual Studio Code? 的重复,因为这是关于 VSCode 中的简单调试,而不是进入 BCL。

【问题讨论】:

    标签: c# debugging visual-studio-code .net-core


    【解决方案1】:

    是的,这是可能的。
    您已经提到的两个链接很有价值,但还有一个链接https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md

    首先,检查“launch.json”配置文件

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "example name",
                "type": "coreclr",
                "request": "launch",
                "preLaunchTask": "build",
                "program": "${workspaceFolder}/src/app/bin/Debug/net6.0/app.dll",
                "args": [],
                "cwd": "${workspaceFolder}",
                "console": "internalConsole",
                "stopAtEntry": false,
                "justMyCode": false, // should be false, as we want to debug 3rd party source code
                "requireExactSource": false, // https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#require-exact-source
                "suppressJITOptimizations": true, // it's better to set true for local debugging
                "enableStepFiltering": false, // to step into properties
                "symbolOptions": {
                    "searchMicrosoftSymbolServer": true, // get pdb files from ms symbol server
                    "searchNuGetOrgSymbolServer": true,
                    "moduleFilter": {
                        "mode": "loadAllButExcluded",
                        "excludedModules": []
                    }
                },
                "logging": { // you can delete it if all is ok
                    "moduleLoad": true,
                    "engineLogging": true,
                    "trace": true
                }
            }
        ]
    }
    

    开始调试后,“DEBUG CONSOLE”将包含这样的日志

    Loaded 'C:Program FilesdotnetsharedMicrosoft.NETCore.App.0.10System.Private.CoreLib.dll'. Symbols loaded.
    Loaded 'C:Program FilesdotnetsharedMicrosoft.NETCore.App.0.10System.Console.dll'. Symbols loaded.
    

    如果加载某些 pdb 时出现问题,您可以使用 dotPeek 作为本地符号服务器。

    之后,您可以在 vscode 的调试面板中使用“Step Into (F11)”按钮来调试 .net 源代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-30
      • 2018-06-30
      • 2011-10-11
      • 1970-01-01
      • 1970-01-01
      • 2016-08-19
      • 1970-01-01
      相关资源
      最近更新 更多