Is there a way to have an Azure Function App created from multiple .NET projects and have all of the Functions from all of them?

▼魔方 西西 提交于 2021-02-10 18:54:30

问题


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?


回答1:


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)".

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.

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.

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.

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.




回答2:


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.

2 - 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?



来源:https://stackoverflow.com/questions/59170087/is-there-a-way-to-have-an-azure-function-app-created-from-multiple-net-projects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!