DEV Community

Ihor Bodnarchuk
Ihor Bodnarchuk

Posted on

Debugging Azure App Service from Visual Studio

This will later be included in a series of articles I plan on writing about my journey of building a SaaS on Azure.

Today I’m having issues with deployment slots for one of our Azure App Services. For some reason, our Staging slot is using some weird config nowhere to be found within our current codebase that’s deployed out of staging branch. Since ASPNETCORE_ENVIRONMENT is set to Staging I expect out .NET 5 app to use config from appsettings.Staging.json which doesn’t seem to be the case. To troubleshoot I needed to attach debugger to the live app but the steps outlined here https://devblogs.microsoft.com/premier-developer/remote-debugging-azure-app-services/ didn't work. That bug was already reported and supposedly fixed by MS in VS v16.5 yet we are on v16.11 now and the issue is still there. Fortunately, user ZubairMunir-5725 saves the day with his workaround posted here https://docs.microsoft.com/en-us/answers/questions/528107/unable-to-attach-remote-debugger-to-app-service-sl.html
In case the link becomes dead the steps are:
1=> Latest Visual studio
2=> Go to Debug tab
3=> Click on Attach process
4=> In Dialog there is Connection Target paste your site url without http like(myappservice.azurewebsites.net)
5=> Hit the Refersh button
6=> Again dialog apperies add your app service crediential username and password and check remember me
7=> A list of process will be shwon to you just click on the w3sp process .
8=> Now check debuger is attached and now you can debug .
Note:Explanation of step 6 to get cridential
There is two methods to get username and password
1) Download publish profile and open in notepad++ there you can see the username and password.

<publishData>
<publishProfile profileName=”myappservice — Web Deploy” publishMethod=”MSDeploy”
publishUrl=”myappservice.azurewebsites.net:443"
userName=”{USERNAME}” userPWD=”{PASSWORD}” …>
<databases />
</publishProfile>
<publishProfile profileName=”myappservice — FTP” publishMethod=”FTP” …>
<databases />
</publishProfile>
</publishData>
Enter fullscreen mode Exit fullscreen mode

2) you can also get this username and password from azure portal
i)=>Go to azure portal
ii)=>Open your app service
iii=>Developement center
There is three tab on top right side click on FTPS Cridential
there is the username and password .
Note your app has to be in debug mode otherwise when setting up the breakpoint you will see this

Alt Text

We are using Github actions to deploy our code so all I had to do was just update our .yml file located in /.github/workflows replacing Release with Debug

- name: Build with dotnet
run: dotnet build --configuration Debug
- name: dotnet publish
run: dotnet publish -c Debug -o ${{env.DOTNET_ROOT}}/myapp
Enter fullscreen mode Exit fullscreen mode

It can also be accessed via VS by right-clicking your Web project -> Publish…

Alt Text

Just another day in the life of a miserable MS stack developer, happy troubleshooting :)

Discussion (0)