Remotely debug application across the internet

“Remote debugging” typically consists of Visual Studio connecting to a machine on the local network and then debugging a process (application) on that machine just the same as if it were running locally.

Although not advertised, debugging over the internet is also possible.  You can do so with a VPN (virtual private network), and in this article I will explain how to setup a cloud based VPN and begin debugging an application across the internet.  I will use ‘your machine’ to mean the computer with Visual Studio, that you will use to debug from, and ‘remote machine’ to mean the computer with the application running that you want to debug.

Requirements

In addition to VS you’re going to need:

  1. VPN that your machine and the remote machine can connect to (eg. Hamachi is a free cloud VPN service you can use for small networks). This requires VPN client software be installed on your machine and the remote machine.
  2. Remote Debugging tools from Microsoft. Visual Studio includes the remote debugging tools, but they are also available as a standalone download.  This includes msvsmon.exe which must be installed and running on the machine you want to connect to and debug.
  3. Firewall modifications on the remote machine (done for you by the remote debugging tool).
  4. You will need login credentials for an account on the remote computer. This could be an account especially for you, or an existing account, but the remote application needs to be running under that account.
  5. The debug symbols (.pdb files) for the assemblies you want to debug, and also the unoptimized assemblies (eg built in debug configuration) will need to be on the remote machine.

 

Setup

VPN

Assuming a VPN isn’t already setup with your machine and the machine running the application, let’s set one up using the Hamachi service.

–On the machine with Visual Studio (your machine)–

  1. Go to https://www.vpn.net/
  2. While you download and install the Hamachi software, signup for an account (top right of screen)
  3. The signup is for a generic LogMeIn account, but you will use this account to create your VPN, and to connect to it.
  4. When Hamachi is running, login with your account, and create a new network. This network is global and any LogMeIn account can be used to access it.  When you install Hamachi on the other machine (the one to debug) you will need the network name and password.

–On the machine you want to debug the application on (remote machine)–

  1. Download and install Hamachi. You can login with the same account you used on your own machine (not advisable unless this machine is also under your control), or login with a different LogMeIn account.
  2. In Hamachi, join the network you created in step 4.

Look out for warning sign triangles in the Hamachi machine listing; if there are any, these could prevent the remote debug working.  Googling any errors is suggested to resolve them, or comment below.  Personally I encountered these after hibernating and solved it by restarting Windows.

Visual Studio Remote Debugger

The remote machine must be running msvsmon.exe, which is a small application that listens to connections from Visual Studio.  It is included with a Visual Studio install, and it appears that it can be run over a network share, although I haven’t tried that.  It can also be installed with the Remote Tools standalone, but it’s important to use the version that matches the Visual Studio you will use for debugging.

Downloading the Remote Tools installer needs a page for itself; https://msdn.microsoft.com/en-us/library/y7f5zaaa.aspx but you’re probably (unless you have VS 2015 update 3) going to end up at my.visualstudio.com (where you need to login) to get the correct download https://my.visualstudio.com/downloads?q=remote%20tools%20visual%20studio%202015

Remember, this needs to be installed on the remote machine only.

I’m curious whether you could use the VPN to access vsmsmon.exe over a network share, but even so that would require setting up a share on your machine with msvsmon in it, so that the remote computer can access it.  This also suggests though that perhaps the folder with msvsmon.exe in it, could be zipped and just copied to the remote machine.  It typically lives under VS in

\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Remote Debugger

On the remote machine, you can now run msvsmon.exe.  When you do that the first time it will ask to modify the firewall, and you will have to allow it (perhaps disable for public networks).

The Moment Of Truth

At this point it should all be ready to go; the local and remote machines are connected to the same VPN network, the remote machine has an account you can login to, debug symbols are on the remote machine, and it is running msvsmon.exe.

On your machine get the remote machine’s IP address, from the Hamachi window.

VPN window
The Hamachi VPN window

Go to Visual Studio, load the project you need to debug, and choose Debug->Attach to process…

In the Qualifier field, paste the IP address of the remote machine, and press Enter.

Attach to process window
Attach to process window

 

If the VPN and msvsmon.exe are functioning correctly, you will be asked for login credentials for the remote machine.  Here you should enter the account details that belong to the remote machine.

If all has gone to plan, in a moment you will see a list of processes in the grid below.  Select your application and you’re off!

I’m interested in your feedback, do you have a real need for this?  Is it too complicated to setup?  Are the requirements on the remote machine (accounts, installs) a deal breaker?

2 thoughts on “Remote debug .NET applications over the internet with Visual Studio”

  1. That was a very thorough explaination thanks and it was really helpful to some extents. however i faced the fact LogmeIn is not allowing to connect together although both points shows green, but pinging gives Connection timed out. is it a must to have logmein? for example if i can connect directly to SQLDB via my app, I think there should be a way to debug via internet, or may be i am mistaken?

    1. Hi Moustafa, unfortunately I can’t remember exactly why a VPN was needed – all I can say is that I would have first just tried opening up the necessary ports, but that didn’t work.
      You don’t have to use logmein, But you do need a VPN, one way or another.

Leave a Reply

Your email address will not be published. Required fields are marked *