4
votes

Is there a way of sharing common code across two different Function Apps in Azure?

I understand it is possible to share code between two functions under the same Function App like so:

#load "../Shared/ServiceLogger.csx"

but I would like to share logging code between two different functions, each under it's own Function App. The reason for the functions being under two different Function Apps is that I need one to run on the Consumption plan and the other run on an App Service plan, unless there is another way of doing this?

3

3 Answers

7
votes

There is no straightforward way to share code across app boundary in Azure App Sercice, and this holds true both for Function Apps and Web Apps. You will need to deploy the relevant code into each app that needs it.

0
votes

What I did to get around this before the fix in VS17 Preview (which treats functions as normal cs files and allows project references) is I had a shared class project that had a post build event that would put the dlls into the Azure function projects in a folder. Then reference them with #r "file path to the dll"

0
votes

One way to reuse code is to use precompiled assemblies / class libraries with your Functions. Donna Malayeri has published a blog post explaining how to achieve this: https://blogs.msdn.microsoft.com/appserviceteam/2017/03/16/publishing-a-net-class-library-as-a-function-app/

Consequently, you could have 2 or more different Functions, deployed to different AppServices or Function instances sharing the same code through a class library. Precompiled assemblies are supported in .NET C# Functions and you can do something similar using WebPack in Node.js based Functions