Publish Azure Function as NuGet package (or load function from external assembly)

老子叫甜甜 提交于 2020-12-15 05:44:05

问题


I'm looking into publishing a reusable Azure Function as a NuGet package, in order to easily consume it in other projects. This way I can reference the NuGet package in other projects. This way I could dynamically compose a set of Azure Functions to be deployed to an Azure Function service.

Is this currently possible? Or, can functions e.g. be defined in an external assembly, and be "picked up" by the Azure Function host?

I know this is possible with Azure WebJobs, but I haven't found a way to achieve the same result using Azure Functions.


回答1:


Adding <FunctionsInDependencies>true</FunctionsInDependencies> in the .csproj file seems to do the trick.

Do make sure you actually call the dependency somewhere in the code (e.g. in Startup.cs) to make sure the assembly isn't optimized away by the compiler.




回答2:


Azure function host discovers function entry points in the same assembly of host (annotated by FunctionName in Run method). So you will only be able to externalize all the reusable codes to separate nugets, but would still need to define entry point for each of the function in the host. The function body might then be just bare minimum wrapper calling your reusable assets, but needs to be present in host. Would you mind to share a bit more about the scenario you are trying to solve?

EDIT: Thanks @Nsevens for trying this out. <FunctionsInDependencies>true</FunctionsInDependencies> in the .csproj would load functions from dependencies. There should be an explicit call of some method (may be just a noop one) of the dependency from the host to make it a hard dependency for the compiler. I did not see any official documentation about this.



来源:https://stackoverflow.com/questions/62692730/publish-azure-function-as-nuget-package-or-load-function-from-external-assembly

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