Debugging is one of the key features used by every developer in any kind of development platform or language. However, to fix some critical issues, sometimes debugging has to be done for the application which is already deployed in the server.
We know that the process can be attached to an application to debug, but how do we do this for the application hosted in Azure? You will get an answer here, with simple steps.
Step 2
Open your project in Visual Studio. Set the debug breakpoint at any line of the code you wish to debug.
Step 3
Right-click the solution and choose the “Publish” option, which will give you a screen like the one shown below. Based on the Visual Studio version you are using, the screen UI will differ.
Click the “Import Profile” option. At the bottom, next to cancel, there is a settings icon. Click the settings icon to switch the mode from Publish to “Create Profile”
Step 5
Now click “Create Profile” at the bottom. It will open a FileDialog to select the publishing profile which you downloaded in Step 1. It will configure the AppService to be available for publishing from Visual Studio.
Step 6
By default, publishing profiles will be configured to build and publish in Release mode. However, here we are going to debug, so we need to configure the publish profile to build and publish in Debug mode. To do that, go to the settings section, as shown below:
Step 7
In the next screen, choose “Settings” from the left menu and in the configuration option, choose “Debug”, then click save.
Step 8
Now, click the Publish button in the Publish Wizard. Your debug build along with debugger information will be published to the Azure App Service.
Step 9
Now time to enable remote debugging. In your Visual Studio, go to View -> Server Explorer. In the server explorer, configure your Azure account, which will list all your AppServices in the account.
Step 10
Right-click on the AppService that you published in Step 8 and choose “Attach Debugger” as shown below. It will publish your app again and convert your Visual Studio in debug mode.
We are all done. If you have placed the debug breakpoint in the start-up file itself, you will get a debugging hit in the page load itself. Elsewise, the breakpoint will hit when the specific functionality is executed.
Once your debugging is done, you can again configure the Publish Profile as Release mode and publish again, because we cannot leave the debug mode to run in the server.
I hope this article helps you to debug your Azure App Service. If you have any questions/issues about this article, please let me know in the comments.