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.

Automation

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.

$rtoolsdownload="public_dropbox_link_to_rtools"
Invoke-Command -Session $adminSession -ScriptBlock {
    param([String]$file)
    $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
}

VPN

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.

vpn1

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.

vpn2

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.

vpn3

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.

vpn4

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

Debugging

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.

attach_to_process
Easy as that.

TLDR

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

References

Remote debugging and diagnostics on MSDN.

About erictummers

My work as a recruited developer changes almost every month. 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:

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s