Day to day, I work in a Visual Studio solution that has a dozen or so projects. One of the projects holds six or seven Azure Functions. Some of the functions are triggered by messages showing up in a ServiceBus queue, some are triggered by HTTP POSTs, and some are triggered by timers.
There are times when I’m debugging that I don’t necessarily want all of the functions running, especially those that are on a timer. Sure, I could modify the cron string to not have them fire as often, but sometimes I just want to debug a single function in isolation without having to worry about the others being executed.
In the host.json file within the project, it’s as simple as adding a new section for “functions” and listing the specific functions you want to execute when running from Visual Studio. If the section doesn’t exist, or the array is empty, all functions will be executed. This is intended for use when running the functions locally.
I created an example project to illustrate what I’m talking about. The functions in this project are WebhookFunction, PollingFunction, and QueueProcessingTrigger.
By default, the host.json will look something like this:
As you can see, there is no section for functions, so all functions will execute when the project is run.
If I only want to run the WebhookFunction when I hit F5, I can add it to the “functions” array. Anything else will be ignored.
When I’m done with my focused testing, I can revert the changes to this file, clear the array, or delete the entire “functions” section.
There is another way to disable specific functions from running in Visual Studio. You can add a line per function to your local.settings.json to disable the function. Where the solution above won’t attempt to run them, this method seems to be a bit different in that it shows the function is disabled when running the project.
In this case, I set the PollingFunction to disabled. Notice in the Azure console, it shows it’s disabled versus the earlier screenshot of the console where it didn’t even mention the PollingFunction.
I hope you found this to be informative and useful, and I hope it makes your debugging sessions with Azure Functions a bit simpler!