Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I start the debugging process on a remote computer?

I'm setting up a Visual studio remote debugging session for a standard Windows Forms application written in C#.

On the Internet are a lot of stories about how to set up the remote computer and MSVCMON.EXE, but I can't find any stories about what to do on my computer to make sure that my program is debugged on the remote computer when I press START DEBUGGING.

So what should I do to make remote debugging possible?

like image 850
Harald Coppoolse Avatar asked Oct 22 '13 07:10

Harald Coppoolse


People also ask

How do I run remote debugging?

Set up the debugger First, we need to set up the run/debug configuration that will be used for attaching to the host application. From the main menu, select Run | Edit Configurations or press Alt+Shift+F10 then 0 . and select Remote JVM Debug.

How do I start a process in debug mode?

Spawning a new process on the same computerIn Visual Studio, from the Tools menu, choose Launch Under Debugger. In the Launch Under Debugger dialog box, enter the path to the executable file. You can also enter arguments and a working directory. Click Launch.

How do I debug a remote process in Visual Studio?

You can attach the Visual Studio debugger to a running process on a local or remote computer. After the process is running, select Debug > Attach to Process or press Ctrl+Alt+p in Visual Studio, and use the Attach to Process dialog to attach the debugger to the process.


1 Answers

After some research I have found how to do it, even if you are working in a company that has a lot of safety issues with firewalls, etc. The only thing that I need from the IT department is administrator rights on both computers.

Prerequisites:

  • I used this method in Visual Studio 2012 Professional and tested it again a few years later in Visual Studio 2013 Ultimate.
  • Both the local computer and the remote computer were in the same domain.
  • I logged in as a member on the domain.

How to do it:

  • On the remote computer: log in using your normal account. If this is the first time a new environment is created for you.
  • On the remote computer: make sure you have administrator rights.
  • On the remote computer: enable remote desktop.
  • On the local computer find the remote debugging folder of your Visual Studio.
  • On my computer this was: "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\Remote Debugger"
  • Copy this folder to a similar (findable) folder on the remote computer.
  • On the remote computer run MsvsMon.exe from the copied folder.
  • The first time it will do some installation. Let it change the firewall.
  • Use Tools Options - Windows Authentication
  • Use Tools Permissions to make sure you are a user that has debug rights.

The msvsmon.exe program should now be waiting for new connections. The name of the server is something like "remote computer name" : "port number", for instance Prototype1:4016.

Now on the local computer where you will develop your program using Visual Studio do the following:

  • Open Visual Studio, and load the solution.
  • If not already done so: set the startup project (right click on the startup project and select start as start-up project.
  • Start the configuration manager (click on arrow next to the combobox with the debug / release selection and select configuraton manager...).
  • In the configuration manager "Active solution configuration" select new. Give the new configuration a proper name, and make it a copy from Debug (probably).
  • When creating code for your remote debugging, you'll have to select the new configuration.
  • Some settings of this new configuration need to be changed. For instance, you'll have to make sure that after building the result code is on the remote computer. The easiest way is to double click the properties of the start-up project and select the build tab. Change the output path from bin\debug to the location on the remote computer where you want the code. For instance: \\Prototype1\Users\Harald\Documents\CameraTestProgram\.
  • In the same properties form, on the Debug tab, select on which computer the debug session should be: check: use remote machine" and fill in the same name as in the MsvsMon.exe. In my example: type Prototype1:4016.
  • In Visual Studio build your code, set your breakpoints and start debugging.
  • Use remote desktop connections to control your windows form.

This method works if you want to debug a normal Windows Forms application written in C#. I detected that it even works if you use unsafe code. There are some warnings though if your program contains C++ code, but they can be ignored.

Microsoft links for this (worked October 2013, and still in August 2015):

  • Microsoft description on how to setup remote debugging. This link does not work anymore on June 2017.

  • Microsoft: how to set up remote debugging. It worked in June 2017

like image 125
Harald Coppoolse Avatar answered Nov 18 '22 07:11

Harald Coppoolse