Visual Studio: auto attach to a process when the process is spawned

When I've faced this situation before (and I controlled both processes), I found a decent workaround is to put a call to Debugger.Launch() in the spawning process' entry point. VS will then pop up a dialog box and let you attach to the process.


See the MSDN article, How to: Launch the Debugger Automatically - this would allow one to skip the plethora of busywork clicking confirmation dialog boxes [without turning off UAC or other messing]. The article lists the following steps:

  1. Start the Registry Editor (regedit).
  2. In the Registry Editor, open the HKEY_LOCAL_MACHINE folder.
  3. Navigate to HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\currentversion\image file execution options.
  4. In the Image File Execution Options folder, locate the name of the application you want to debug, such as myapp.exe. If you cannot find the application you want to debug:
    a. Right-click the Image File Execution Options folder, and on the shortcut menu, click New Key.
    b. Right-click the new key, and on the shortcut menu, click Rename. c. Edit the key name to the name of your application; myapp.exe, in this example.
  5. Right-click the myapp.exe folder, and on the shortcut menu, click New String Value.
  6. Right-click the new string value, and on the shortcut menu, click Rename.
  7. Change the name to debugger.
  8. Right-click the new string value, and on the shortcut menu, click Modify. The Edit String dialog box appears.
  9. In the Value data box, type vsjitdebugger.exe.
  10. Click OK.
  11. From the Registry menu, click Exit.
  12. The directory containing vsjitdebugger.exe must be in your system path. To add it to the system path, follow these steps:
    a. Open the Control Panel in Classic view, and double-click System.
    b. Click Advanced System Settings.
    c. In System Properties, click the Advanced tab.
    d. On the Advanced tab, click Environment Variables.
    e. In the Environment Variables dialog box, under System variables, select Path, then click the Edit button.
    f. In the Edit System Variable dialog box, add the directory to the Variable value box. Use a semicolon to separate it from other entries in the list.
    g. Click OK to close the Edit System Variable dialog box.
    h. Click OK to close the Environment Variables dialog box. i. Click OK to close the System Properties dialog box.
  13. Now, use any method to start your application. Visual Studio will start and load the application

Another nice Solution is to use the Visual Studio Extension "ReAttach". Can be found here.

If your process is not currently running, ReAttach will ask you to start it and attach to it as soon as it becomes available.


I have been looking for some way to do this when I launch a console application within an acceptance test.

I found this today - https://blogs.msdn.microsoft.com/visualstudioalm/2014/11/24/introducing-the-child-process-debugging-power-tool/

It's an add-on to visual studio, and it works a treat. When I debug an acceptance test (I use resharper test runner) and place a breakpoint within the app that gets launched, I can now debug the app in the same visual studio instance.