56

I wonder if I can run multiple instances (right now two instances) of my application in debug mode by doing a simple click or set a key for that...

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
MCA
  • 761
  • 2
  • 9
  • 15
  • No, you can't run multiple instances of your application from Visual Studio. Features like "Edit and Continue", for example, can only work if there's a single instance. You can, however, run multiple instances from *outside* of Visual Studio, but you'll lose some of these fancy features. – Cody Gray - on strike Mar 31 '11 at 11:32
  • I can run multiple instances of my app and debug them in the same VS enviroment. I just want to know if I can do that by pressing a key or a click to a button.. – MCA Mar 31 '11 at 11:40
  • I assume you're talking about something like that discussed [here](http://stackoverflow.com/questions/447840/debug-multiple-copies-of-a-program-from-one-vs-instance)? More specifically, you run multiple instances manually, and then attach the debugger? No, there's no automated solution for doing this; it's not a common use case. Try writing a macro. – Cody Gray - on strike Mar 31 '11 at 11:43
  • possible duplicate of [Run multiple copies of an app from Visual Studio](http://stackoverflow.com/questions/2963848/run-multiple-copies-of-an-app-from-visual-studio) – Cody Gray - on strike Mar 31 '11 at 11:43
  • Yeap I have read that thread, and that's how I run multiple instances. I just thought if there's an easy one click way to do it.. I guess there isn't. Thank you. – MCA Mar 31 '11 at 12:57
  • As I mentioned before, I think creating a simple macro might work for you. I can't turn that into a full answer because I've never done it before myself and I don't really know for sure if it would work. But this *sounds* like the ideal candidate to be solved with a macro. Read more about that [here on MSDN](http://msdn.microsoft.com/en-us/library/b4c73967.aspx). – Cody Gray - on strike Mar 31 '11 at 12:59

4 Answers4

130

Not many people seem to know this, but this is perfectly possible, though I admit it's not very obvious. Here's what you do:

  • suppose your current project is A, and it's output is c:\bin\my.exe
  • add an empty project to the solution for A, call it 'Dummy'
  • under Dummy's Project Properties->Debugging set the Command to point c:\bin\my.exe
  • under Solution Properties->Configuration Manager, uncheck all builds of the Dummy project so VS won't try to build it (building an empty project fails)
  • under Solution Properties->Startup Project, select Multiple Startup Projects and set the Action for both A and Dummy to Start
  • now hit F5 and your exe will be launched twice, each under a seperate debugging instance. (as you will be able to see in the Debug->View->Processes window)
stijn
  • 34,664
  • 13
  • 111
  • 163
  • 3
    Great answer! BTW In VS2010 I needed to set _Project Properties|Debug|Start Action|Start external program_ and also _Project Properties|Debug|Start Options|Working directory_ – Erik Vullings Jul 11 '12 at 14:31
  • 1
    you're welcome :] I stumbled upon this when wanting to debug client/server applications simultaneously. For such cases this workflow is simply amazing: 1 source code window with the client code, next to it 1 with the server code, and step-by-step debugging at your hands. – stijn Nov 30 '12 at 14:03
  • Nice! I wanted to run two instances of a test program that exercises a library. I used the library project in lieu of a dummy project, setting its debugging Command to "$(ProjectDir)test\$(Platform)\$(Configuration)\test.exe" - so both instances of the test program use the selected config and platform. – yoyo Jul 08 '20 at 17:43
  • What if your target platform is not Windows and you don't have an .exe? In example Xamarin or MAUI apps or a webapp... – Windgate Jul 26 '23 at 10:58
10

You can use "Multiple Startup Projects" feature, but avoid creating dummy projects by hand: just add your debuggee executable into the solution directly:

  • Solution > Add existing project > Path to .exe

If you neeed several instances, Visual Studio won't allow you to add the same executable twice, but adding a symlink to it with another name works as expected.

MSDN: How to: Debug an Executable Not Part of a Visual Studio Solution

Vladimir Sinenko
  • 4,629
  • 1
  • 27
  • 39
2

Is Visual Studio 2013 this is even easier!

Project-> Properties -> Debug -> check "Start external program" and click the ... button, navigate to your .exe of the other program.

Then Make sure in your Solution -> Properties -> MultipleStartup Projects that it's checked.

Fred Johnson
  • 2,539
  • 3
  • 26
  • 52
  • What if your target platform is not Windows and you don't have an .exe? In example Xamarin or MAUI apps or a webapp... – Windgate Jul 26 '23 at 10:58
-2

You can run two instances of your application from where it is built; example: d:\test\bin\debug\app.exe and attach both instances to the Visual Studio 2010 debugger.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ViV
  • 1,998
  • 8
  • 27
  • 54
  • 1
    This is possible, but this does not answer this question, as this is not "a simple click or set a key for that". Moreover, attaching debugger after the app is run is sometimes not sufficient, as you miss the app initialization this way. – Suma Dec 06 '12 at 09:06