Until now, it wasn’t possible to locally debug Azure Functions. However, with the release of Visual Studio v15.3, this has now become possible. As part of the Azure development workload, Microsoft have introduced ‘Azure Function Tools’ that lets you locally test your Azure Functions.
This toolkit came at a very appropriate time, as recent project that we have worked on required such a functionality so it was fully utilised for our testing purposes. Yet there are some pre-requisites before the toolkit can be installed:
- Install Visual Studio 15.3 (or later)
When you have started installing Visual Studio, you should get a screen where you should be able to select various different workloads. Select ‘Azure development’. This will install the relevant SDK and tools needed including ‘Azure Function Tools’. If you already have Visual Studio 15.3 (or later) installed and wish to just install the standalone ‘Azure development’ workload then follow the below steps:
- Find Visual Studio Installer on your computer
- Click to start the installer, and then select Modify.
- From the Workloads screen, select Azure development.
- Click Modify
- After the workloads have been installed, click Launch.
Now that we have all the tools we need installed, we can start using the toolkit right away. Click on File -> New Project and then Azure Functions type (under Visual C# -> Cloud pane on the left-hand side).
Once the project has been created, you would code as normal using classes, interfaces etc. The important file however is the local.settings.json file which is created upon project creation. This is equivalent to Azure Function ‘Application Settings’ in the Azure Portal. The local.settings.json file is where the developer stores setting information such as connection strings used for running the function on the development machine.
Note: For all trigger types except HTTP, you need to set the value of AzureWebJobsStorage to a valid Azure Storage account connection string.
To add more Functions to the project right click the project and choose “Add Item”, then choose the “Azure Function” item template. On the launch dialog select the sort of function trigger you require and providing a name for the functions and a connection string.
You can debug as develop locally as normal, debug it, add NuGet Packages, create unit tests and the like.
To then publish the app in Azure, right click on the project and select ‘Publish’. On the dialog that opens you can either create a new Azure Function or add to an existing function.
Note: The folder option is not intended to be used with Azure Functions at this time, though it is shown in the options.
And That’s it! As easy as that. This tool is definitely worth the effort and time so give it a try!