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.
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.
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
- open the VPN tunnel,
- remote desktop to the machine to start the remote debugging tools,
- start visual studio and attach to the remote machine for debugging.
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.