Visual Studio Remote Debugging

Do you run Sitecore remotely but want to debug your code locally? Visual Studio supports remote debugging. There are a number of websites that describe how to configure remote debugging, but some things bear repeating.

I am writing this post with a specific scenario in mind: Sitecore is running in a virtual machine and Visual Studio is running on my local machine.  I want to be able to develop my code locally, deploy to the virtual machine, and debug my code locally.

My local machine is running Windows 7. I log into an Active Directory domain. My virtual machine is running Windows Server 2008 R2 on VMware Workstation 7.1.

The first step is to configure the remote debugger service on the virtual machine (which, in this setup, is also called the remote machine). This service must run using a local account with the same user name and password as the account I log into my local machine with (meaning the account that is running Visual Studio).

  1. In the virtual machine, create a local Windows account. This account must have the exact same user name and password as the user that runs Visual Studio. This account must also be a member of the Administrators group.
  2. In the virtual machine, click Start > Administrative Tools > Local Security Policy.

  3. Navigate to Local Policies > User Rights Assignment and double-click Log on as a service.

  4. Add the local user created in the first step.

  5. Close the Local Security Policy window.
  6. Download and install the Visual Studio 2010 Remote Debugger on the virtual machine. When the configuration wizard appears, enter the user name and password for the local user created in the first step.

  7. The wizard will configure the firewall to allow remote debugging traffic. The value you pick here depends on your network configuration. For my network, the default option is sufficient.

  8. When I open the Windows services configuration screen I can see the remote debugger service is running using the new local account.

The next step is to configure the local machine. If you log into your local machine with a local user account, this step can be ignored. However, if you log into your local machine using a domain account, there is an additional step. In order for remote debugging to work, I need to create a local account with the same user name and password as my domain account. This account should also be a member of the local Administrators group.

Now I am able to use remote debugging. In Visual Studio, when I want to debug I use the menu option Debug > Attach to Process.

In the Attach to Process screen, I enter the name of my remote server in the Qualifier box and press the Enter key. Visual Studio shows a list of processes I can debug. Sitecore runs in the w3wp process, so I select that process and click the Attach button.

Here are a couple of other notes that should help you get started:

  • Be sure that debugging is enabled in the Sitecore web.config file.
  • After you compile your code, you need to deploy the dll and pdb files to the Sitecore bin folder.
  • Connect to the remote server BEFORE the .NET assemblies are loaded, otherwise the symbols do not get loaded and you will not be able to debug. For example, compile your code, deploy your files, attach to process, then load Sitecore in your browser.

  • Adam, this is the exact way I've been working for four+ years now! Local Visual Studio with Sitecore(s) running on a Virtual Machine. I actually documented it here:  How do you handle the pushing of compiled code to your VM? I used to use post build steps, but this clunky'ness one of the reasons we created TDS.  You should be able to remove the need to "Attach to Process" too. On the 'Web' tab of the properties for your Web Application project you should choose the "Use Custom Web Server" option and enter in your development Sitecore URL. Once this setting has been specified you can now press F5 to build your project and debug normally. This may require some IIS components to be enabled, depending on your system.