Debugging by Using Visual Studio
Updated: November 22, 2010
The Windows Azure Tools for Microsoft Visual Studio combined with the Windows Azure SDK enables you to debug your application before you deploy it to Windows Azure. You can use the information in the following sections to help you debug your application:
Debugging an application in the Windows Azure emulation environment
Debugging an application by using IntelliTrace in Visual Studio
You can debug your application from within Visual Studio while you are developing it, as you would any Visual C# or Visual Basic application. You can also use the compute emulator to run your application locally for testing and debugging before you deploy it to Windows Azure. For more information about using the compute emulator, see Use the Windows Azure SDK Tools to Package, Run, and Deploy an Application.
When you debug or run your application from Visual Studio, the compute emulator is automatically launched in the background and your application is deployed as a service in the compute emulator.
To debug your application in Visual Studio, select Start Debugging from the Debug menu. Alternatively, you can select Start without Debugging to run the application in the compute emulator without debugging.
To display the user interface of the compute emulator, right-click the Windows Azure icon in the system tray and click Show Compute Emulator UI. The following image shows an example of the user interface of the compute emulator:
The left pane of the user interface shows the role instances that are currently running in the compute emulator. You can click on the service or roles to display lifecycle, logging, and diagnostic information in the right pane. If you click in the top margin of a message window, it expands to fill the right pane. If you are debugging your service, you can step through the service using the commands on the Debug menu, as well as set breakpoints in your code. As you step through the application in the debugger, the panes are updated with the current status of the service. When you stop debugging, the service deployment is deleted. If you run without debugging, the service deployment continues to run until you explicitly stop it.
|When you stop running or debugging your application, the compute emulator and storage emulator are not stopped. You must stop them explicitly from the system tray.|
If your application includes a web role and the Startup action property is set to launch the web browser, Visual Studio launches your application in the browser. You can modify the configuration of an application while it is running in the debugger. However, if you add additional instances of a role to your application while it is running, the debugger does not automatically attach to the new running processes. To debug the new instances, you must explicitly attach to their processes. From the Debug menu, select Attach to Process, select the new WaHostBootstrapper.exe processes, and then click Attach. If you stop debugging and then restart your service in the debugger, the debugger automatically attaches to all running instances of a role.
By default a Windows Azure project is also configured to launch the storage emulator on run or debug. For more information about using the storage emulator, see Overview of Running a Windows Azure Application with the Storage Emulator.
You can use the Windows Azure Diagnostics Monitor to collect diagnostic data. By writing trace data to the output window, you can use the diagnostic data to debug your application. For more information about collecting diagnostic data, see Collect Logging Data by Using Windows Azure Diagnostics.
With IntelliTrace debugging, you can log extensive debugging information for a role instance while it is running in Windows Azure. If you need to track down a problem, you can use the IntelliTrace logs to step through your code from within Visual Studio as though it were running in Windows Azure. In effect, IntelliTrace records key code execution and environment data while your service is running, and allows you to replay the recorded data from within Visual Studio. For more information on IntelliTrace, see Debugging With IntelliTrace.
|IntelliTrace debugging is intended for debug scenarios only, and should not be used for a production deployment.|
|IntelliTrace debugging is available only for Visual Studio 2010 Ultimate, 64-bit edition, and only for Windows Azure projects developed against the .NET Framework 4. You can use IntelliTrace with Visual Studio 2010 Ultimate, 32-bit edition if you install a required QFE.|
You can enable IntelliTrace debugging only for an application that has been deployed from within Visual Studio. You must configure IntelliTrace debugging for your application before you deploy it to Windows Azure. If you have not configured it for an application, but your application is already being hosted as a service in Windows Azure, you must redeploy the application by using Visual Studio. For more information about deploying the application, see Deploying a Cloud Service from Visual Studio.
When you are ready to deploy your application, ensure that the build targets for your project build are set to Debug, right-click the project in Solution Explorer, and then click Publish. To enable IntelliTrace, select Enable IntelliTrace for .NET 4 Roles.
After you enable IntelliTrace, you can customize the IntelliTrace configuration. To do this, click Settings in the Deploy Windows Azure Project dialog box. You can specify which events to log, whether to collect call information, which modules and processes to collect logs for, and how much space to allocate to the recording.
The IntelliTrace log is a circular log file of the maximum size specified in the IntelliTrace settings (the default size is 250 MB). IntelliTrace logs are collected to a file in the file system of the virtual machine. When you request the logs, a snapshot is taken at that point in time and downloaded to your computer.
After the application is deployed to Windows Azure, the Server Explorer indicates whether a deployment has IntelliTrace enabled. The following image shows an example of the structure listed in Server Explorer:
You can download IntelliTrace logs for a role instance from the Server Explorer. Expand the Windows Azure Compute Explore until you locate the instance you are interested in, right-click the role instance, and then select View IntelliTrace Logs. The IntelliTrace logs are downloaded to a file in a directory on your computer. Each time you request the IntelliTrace logs in this way, a new snapshot is created. You can continue working in Visual Studio while the IntelliTrace logs are downloading. Once the log has finished downloading, it will automatically open in Visual Studio.