3

We have an Azure Function App that has multiple Functions, and was created using .NET project (Name: Project1).

We want to add a new Azure function from a different .NET project (Name: Project2) to the existing Azure Function App without overwriting the existing functions that were deployed from Project1. Currently when we deploy Azure Function from Project2 the functions from Project1 gets removed, the Function App contains only the Project2 functions.

We deploy the function using the Azure DevOps release pipelines, and we have also tried publishing from Visual Studio - both behave the same way.

So, is there a way to retain the functions from Project 1 - have functions from both the .NET Projects?

Gour Gopal
  • 581
  • 7
  • 22
  • Not get your latest information, is the following workaround helpful for you? Or if you have any concern, feel free to share it here. – Hugh Lin Dec 09 '19 at 01:24

3 Answers3

2

As far as I know, there's no good solution to your needs, but there is a solution which is not so good for your reference.

I have created an function app on azure portal named "huyrFirstFunapp" and there is a function "Function1" in it. Click "Platform features" --> "Advanced tools (Kudu)". enter image description here

In "kudu" page, navigate to "Debug console" --> "CMD" --> "site" --> "wwwroot". You can see the folder "Function1", a "host.json" and if you have imported some external module, you can also see a "bin" folder".

Now open the visual studio which there is another function project in it. Here I have a project named "hurySecondFunapp" and there is a function "Function2" in it. enter image description here

Right click "hurySecondFunapp" and click "Build", it will generate a "bin" folder and a "Function2" folder, you can find them in the directory shown as below screenshot. enter image description here

Then we need to drag the "Function2" folder from local to "kudu" page(to "wwwroot" directory which we have navigated to). "Function1" folder and "Function2" folder will co-exist in the "wwwroot" directory, and then we need to merge the two "bin" folders. If your two functions are very simple and don't use any other modules, we just need to drag the "hurySecondFunapp.dll" and "hurySecondFunapp.pdb" from "bin" folder in local to "bin" folder in "kudu" page(shown as below), then the function app in azure portal will show two functions in it. enter image description here

But if your two functions are complex and use many modules or external dlls, this solution will not be a good way. We need to merge the differences between the two "bin" folders and maybe it will cause many problems. So just a solution for your reference, I'm not sure if it will work fine in your side.

Hury Shen
  • 14,948
  • 1
  • 9
  • 18
0

A few things come to mind:

1 - Add the function as a link from Project 2 to Project 1. This way when the project is built, the function is also included in the output. Also when you edit the function from either project it will change for the other. Essentially you have the same file across the two projects.

List item

2 - (Edit: Apparently functions from referenced projects are not displayed) The other option, which would be cleaner and clearer, is to have a common shared library that contains the function you want to share.

You may also want to consider why you want the function in both function apps because you'll have two functions that are the same deployed twice. Could you extract commonly shared logic into a common service and have two separate functions? Could you call the function from Project 1 to Project 2 using HTTP?

Aaron Zhong
  • 921
  • 8
  • 22
  • Negative - Step 2 doesn't work. The Functions in the running 'client' app are displayed but any functions in a referenced project are ignored. – Brett Rigby Dec 14 '21 at 12:40
  • @BrettRigby thanks for sharing your findings. sounds a little bit strange, are they not included in the build or do you know whether the dlls exist and just not picked up by azure for some reason? – Aaron Zhong Dec 15 '21 at 20:04
0

I ran into a similar scenario and the way I made it work for me is to include the file with the functions in my .csproj file so that the functions I need from project1 get compiled with project2:

<Compile Include="<Path to file in proj1>" Link="Project1Functions.cs" />
Sunny-Dee
  • 87
  • 9