— MartinG (@AtholyMardies) 24. Juni 2017
On Azure Saturday last week in Munich there was a great Azure Functions / Serverless session by Sia. On a question from the audience on how to debug Azure Functions, he stated that there is not really a good way on how to do that. I was a little suprised about that statement, so let’s discuss that a little more in this blog article.
Please note: I won’t discuss Azure Functions basics, what it is and if it’s something you want to use. That makes this blog post very short. If you follow me, serverless is the way to go in this article. Do it or not – there is no “why?” !
First things first
When you start developing Azure Functions you will find the portal experience poor. So get your Azure Functions development integrated in your local Visual Studio 2017 by following https://blogs.msdn.microsoft.com/webdev/2017/05/10/azure-function-tools-for-visual-studio-2017/ .
What the article does not mention is that you also require to add the Azure Functions cli tools from https://marketplace.visualstudio.com/items?itemName=AndrewBHall-MSFT.AzureFunctionToolsforVisualStudio2017
for local testing and debugging. While it will clearly tell you that requirement when you try to run a function on the local debugger, it’s a good idea to prepare your environment with some basics before you start developing.
At the moment of writing, it’s still the case that Azure Functions integration is available in Visual Studio 2017 preview only, so please double-think about using this in production. In my case, getting experimental is accepted. Don’t use it in production if you’re not sure what you’re doing, kids!
Using the extensions, please note that you can start developing pre-compiled C# functions instead of script based functions. The links above already showed you ho to start your own project. Maybe Sia referred to that limitation when he mentioned that debugging functions is very poor. As I’m working on C# code all the time, that does not affect me.
Once installed you can develop and debug your function in your local Visual Studio installation as any other application. Breakpoints and all the other stuff will work as you’re used to do that for all the ASP.NET / Web API projects.
You can debug Azure Functions issues locally when you used the Azure Functions extensions in VS2017. The Debugger tool can help you find problems and understand how your code works in depth.