Visual Studio - different sets of breakpoints

2019-09-07 05:35发布

问题:

In Visual Studio (2015 and newer), is it possible to have multiple sets of breakpoins? I have several scenarios, I need to debug, but for each of them I would like to have different set of breakpoints. It is quite time-consuming to enable/disable them manually.

回答1:

You can export and import breakpoints from the breakpoints window and then import them as required.

Alternatively, if you don't mind modifying your code, you can use conditional breakpoints and set the condition in your code. E.g., set a boolean testingScenario1 = true and then set a breakpoint condition on the breakpoint to only break when testingScenario1 == true.

Or use Debugger.Break(). Something like:

#if DEBUG
    if (testingScenario1)
        Debugger.Break();
#endif