Remote debugging in Visual Studio 2017

Kailash Chandra Behera | Sunday, January 28, 2018


This blog describes how to debug your .NET source code with the application you have developed and is running in remote computer or server.

Getting Started

Remote debugging is the most valuable feature provided by Microsoft Visual Studios. This feature is available from Visual Studio 2005.
Remote debugging enable the developer to debug his/her source code with the installed desktop application, hosted web, or service application with a local or remote server.

For example
We all know that to identify errors or bugs in our local source code we take help of debugging, but let’s say you are developing a web application and you found that no error in your source code and is running as per your requirements.
After examining source code, you hosted in the server then you found that your application is not running accordingly to your requirement.
In this scenario what will you do, you might be helpless. To tackle errors in this kind of scenario Microsoft Visual has provided remote debugging features.

Setup Remote Debugger

The setup for remote debugging in Visual Studio is quite simple. Msvsmon.exe has a user-friendly interface that makes it easier to use, you need to run Msvsmon.exe on the remote server prior to debugging. You can find the Msvsmon.exe file from below directories

Program Files (x86) \Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Remote Debugger\x86\msvsmon.exe
Program Files (x86) \Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Remote Debugger\x64\msvsmon.exe

    Steps to setup
  1. Locate the Remote Debugger folder and copy the folder to the location or server where you have hosted your web application or desktop application.
  2. If you are running the remote debugger on a remote server, you can right-click the Remote Debugger app and choose Run as administrator. If you are not running it on a remote server, just start it normally.
  3. When you start the remote tools for the first time (or before you have configured it), the Remote Debugging Configuration dialog box appears.

  4. If the Windows Service API is not installed (which happens only on Windows Server 2008 R2), choose the Install button.
  5. Select the network types you want use the remote tools on. At least one network type must be selected. If the computers are connected through a domain, you must choose the first item. If the computers are connected through a workgroup or homegroup, you need to choose the second or third item as appropriate.
  6. Choose Configure remote debugging to configure the firewall and start the tool.
  7. When configuration is complete, the Remote Debugger window appears and the remote debugger is now waiting for a connection. Make a note of the server name and port number that is displayed, here I have rubbed in red color the server name and port number will be displayed like below text.

    Msvmon started a new server named ‘servername:PortNo’ Waiting for new connection

  8. Open your source code in Microsoft Visual Studio, go to ‘Debug’ menu and click on ‘Attach to Process…’ menu. The following window will be opened.

  9. Enter the target machine name and port(Displayed in the Remote Debugger Window) in the field of Connection Target.
  10. After entering above, you will get the list of processes are running in the remote computer or target computer, select the process to which you want to debug and click ‘Attach’ button.
  11. Now you are done with Remote debugger setup and you will find that your source code is in debug mode.