Search code examples
azureazure-web-roles

Azure website debugging


I understand that I can debug an Azure Web Role using the methods outlined here: http://msdn.microsoft.com/en-us/library/windowsazure/ee405479.aspx

What's the process for debugging a Windows Azure Website?

I'd like to be able to step through code, set breakpoints, ect.


Solution

  • UPDATE: The Azure portal has changed and the Application Settings blade is being retired.


    I think this deserves an updated answer for recent versions of the Azure Management Portal and VS.

    This is how I achieved remote debugging for an ASP.Net Core 2.0 API using Visual Studio 2017 Preview 7.1:

    1. Open the Azure Management Portal, browse to your Web App, click Configuration > General Settings, and turn on remote debugging. Previously it also asked for the VS version but this doesn't seem to be an option any longer, I'm assuming the remote debugging platform now auto-detects (but it may also be the case that VS versions prior to 2015 are no longer supported, see comments below)

    enter image description here

    1. Edit your publishing profile and set the configuration to Debug then republish the API to Azure:

    enter image description here

    1. Set breakpoints in your code
    2. Open the Server Explorer pane in Visual Studio, and if you're not already connected to Azure with your Microsoft account, connect it.

    3. Open Azure > App Service > [Resource Group] then right click your web app and select Attach Debugger. After a bit of configuration, it should attach and (if configured) VS will open a browser to your Azure web app.

    enter image description here

    enter image description here

    1. Hit your website/API and your breakpoint should be hit.

    Final notes I've collected:

    • I have noticed that occasionally the "Attach Debugger" option is missing from the menu. It appears that selecting Stop from the menu (wait) then selecting Start is enough to make the option appear again, if stopping the service is an option. There may be other fixes.
    • Some official documentation
    • Don't forget to change the configuration on your publishing profile back to Release, and republish the Release version. Don't use Debug in production. Thanks @Manfred.
    • Avoid long stops at breakpoints (Can anyone explain what the impact of this might be?)
    • It appears that after 48 hours, the remote debug feature is automatically turned off (cannot confirm this yet)