How to start a child process in the same Visual Studio debugging session as the parent, programmatically?

后端 未结 4 1820
攒了一身酷
攒了一身酷 2020-12-15 05:28

When running a process under the debugger, I would like to start a child process in the same debugger.

Currently, I use

Process.Start(\"sample.exe\")         


        
相关标签:
4条回答
  • 2020-12-15 05:43

    Assuming that sample.exe would be the host for code you want to debug, you can use project properties -> debug settings - choose action as an external program and provide path to sample.exe. The VS will start this executable and attach the debugger to it.

    0 讨论(0)
  • 2020-12-15 06:02

    You should attach debugger to process you are starting. This could be done:

    1. Manually from Visual Studio after starting "sample.exe" select it menu Debug > Attach to process..
    2. Programmatically attach debugger inside "sample.exe"
    3. Attaching to a Process using VS.NET Automation Model
    4. UPDATE: You can setup windows environment to attach debugger every time "sample.exe" starts: Launch the Debugger Automatically (you will need to call Debugger.Break anyway)
    5. Some external tool maybe

    Here is code for "sample.exe" to attach debugger:

    if (!Debugger.IsAttached)
         Debugger.Launch();
    Debugger.Break();
    

    You should pass some parameter to "sample.exe" to verify if you need to attach debugger.

    Process.Start("sample.exe", "Debug=true");
    
    0 讨论(0)
  • 2020-12-15 06:09

    you can change the properties of your solution to start multiple apps.

    an explanation is here Run Multiple projects

    The MSDN article is here MSDN Article on running multiple projects

    0 讨论(0)
  • 2020-12-15 06:09

    Visual Studio Debugger Team created an extension that does that automagically: https://marketplace.visualstudio.com/items?itemName=vsdbgplat.MicrosoftChildProcessDebuggingPowerTool

    0 讨论(0)
提交回复
热议问题