We can debug a production cloud service hosted in Azure through Visual Studio. Yes, you can step through the code of a cloud service hosted in a live production environment! And, its very simple. In this post, I’ll explain how to enable remote debugging on azure cloud service and how to step through code. The remote debugging is disabled by default on a cloud service. It needs to be explicitly enabled when the service is published on Azure. There are two ways. I’ll use pictures to explain, because they speak more than words!
First, when creating the cloud service package to manually upload into the azure…
Second, when publishing a cloud service to the Azure directly through Visual Studio…
In the above dialog:
- First screen, Sign In with your Live Account with Active Azure Subscription and Press “Next” (1)
- Enter the required details on the “Common Settings” tab.
- Click on “Advanced Settings” (2)
- Check “Enable Remote Debugger for all roles” (3)
- Click on “Publish” (4)
The service can now be debugged through Visual Studio.
- Open “Server Explorer” > “Windows Azure”
- Expand “Cloud Services”
- Expand the required “Cloud Service” and expand to the required “Worker Role” or “Web Role”
- Right-Click on it and Click “Attach Debugger”
Once the debugger is attached, set a breakpoint in the code and try invoking the service that will hit the breakpoint. You can now step through the code as if it were running on your local machine!
Things to take care,
- Keep the cloud service project open, the one which is deployed.
- Make sure there are no code changes to the local copy of the project after it is deployed, else stepping through code may not work smoothly.
- If the execution is paused for a long time, step through is done slowly or a lot of execution paths are modified in the editor, the health of the cloud service degrades. The cloud service needs a restart to fix it.