Remote Debugging to Azure VM

After setting up my test environment in Azure, I wanted to do some remote debugging to it. This can be done with the remote debugging tools from Microsoft and Visual Studio. I added some steps to my test environment automation script and now have the option to start debugging when I need to with minimal setup required.


I downloaded the Remote Debugging Tools from Microsoft and put the installer in dropbox. Then created a public link to the file. I just needed a point to download it from.

In a powershell session I download and install the tools.

Invoke-Command -Session $adminSession -ScriptBlock {
    $exe = "c:\remote_debugging_tools.exe"
    Invoke-WebRequest $file -OutFile $exe
    Unblock-File $exe
    Start-Process -FilePath $exe -ArgumentList /q -Wait
} -ArgumentList $rtoolsdownload

To enable remote debugging some security policy settings must change. Details in the references at the end of this post.

Invoke-Command -Session $adminSession -ScriptBlock {
    secedit /export /cfg c:\secpol.cfg
    (gc C:\secpol.cfg).replace("Guest only - local users authenticate as Guest", "Classic - local users authenticate as themselves") | Out-File C:\secpol.cfg
    secedit /configure /db c:\windows\security\local.sdb /cfg c:\secpol.cfg /areas SECURITYPOLICY
    rm -force c:\secpol.cfg -confirm:$false


To add my local machine to the Virtual Network I setup a point-to-site VPN. On the Windows Azure Portal go to the Virtual Network you use for the VM. Go to the Configuration tab and check the Configure point-to-site connectivity. Set the Starting IP (this is a dropdown list when you click it) to something that does not give the red exclamation mark.


Now the section below will notify you it needs a Gateway. Click add gateway. Change the starting IP to the first address in the Usable Address Range (in this case change the last 0 in 4). Now Click Save and wait for the changes to be applied.


On the Dashboard tab the Gateway is displayed as not created. Click Create Gateway, this will take up to 15 minutes. Check back later if the gateway was created.


Open up a Visual Studio Command prompt. Create a selfsigned root certificate with the line below.

makecert -sky exchange -r -n "CN=MyNewNetwork" -pe -a sha1 -len 2048 -ss My "MyNewNetwork.cer"

Upload the MyNewNetwork.cer on the Certificate tab of the Virtual Network in the Azure Portal. Then create a certificate to authenticate the client with the line below.

makecert.exe -n "CN=MyDeveloperNetwork" -pe -sky exchange -m 96 -ss My -in "MyNewNetwork" -is my -a sha1

Now wait for the gateway to be created (yellow) and download the client VPN from the dashboard tab. Unblock the downloaded file and install it.


You’ve now created the VPN and can start a connection.


The previous scripts are all part of my test environment automation script and the VPN is already setup. Now when I want to start debugging I

  1. open the VPN tunnel,
  2. remote desktop to the machine to start the remote debugging tools,
  3. start visual studio and attach to the remote machine for debugging.

Easy as that.


Add Remote Debugging tools setup to your automation script and use point-to-site VPN to do remote debugging.


Remote debugging and diagnostics on MSDN.

About erictummers

Working in a DevOps team is the best thing that happened to me. I like challenges and sharing the solutions with others. On my blog I’ll mostly post about my work, but expect an occasional home project, productivity tip and tooling review.
This entry was posted in Development and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.