Sharing code between functions
In a C# script-based Function App, adding a new file to one of the functions will not make it available to other functions in the application.
To share code between functions, we will need to do the following two things:
- Create a folder named
Sharedat the root level of a Function App, and add shared code files to this folder. The WebJobs SDK (that Azure Functions are based on) watches for any code changes in theSharedfolder and makes sure that the changes are picked up by the functions. - Create
#loaddirectives to the specific location of the shared files in each function that references the shared code.
Note
You can add other folders to the function's watch list by modifying the watchDirectories setting of the WebJobs host here at https://github.com/Azure/azure-webjobs-sdk-script/wiki/host.json.
To show an example of the process, we will create a C# script-based version of the ScoreTweet function.
To share code between C# script-based functions in the same Function...