简体   繁体   English

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

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

I'm looking into publishing a reusable Azure Function as a NuGet package, in order to easily consume it in other projects. 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.这样我可以在其他项目中引用 NuGet package。 This way I could dynamically compose a set of Azure Functions to be deployed to an Azure Function service.通过这种方式,我可以动态组合一组 Azure 函数以部署到 Azure Function 服务。

Is this currently possible?目前这可能吗? Or, can functions eg be defined in an external assembly, and be "picked up" by the Azure Function host?或者,可以在外部程序集中定义功能,并由 Azure Function 主机“拾取”吗?

I know this is possible with Azure WebJobs, but I haven't found a way to achieve the same result using Azure Functions.我知道 Azure WebJobs 可以做到这一点,但我还没有找到使用 Azure 函数实现相同结果的方法。

Adding <FunctionsInDependencies>true</FunctionsInDependencies> in the .csproj file seems to do the trick..csproj文件中添加<FunctionsInDependencies>true</FunctionsInDependencies>似乎可以解决问题。

Do make sure you actually call the dependency somewhere in the code (eg in Startup.cs ) to make sure the assembly isn't optimized away by the compiler.请确保您确实在代码中的某处调用了依赖项(例如在Startup.cs中),以确保编译器不会优化程序集。

Azure function host discovers function entry points in the same assembly of host (annotated by FunctionName in Run method). Azure function 主机在同一主机程序集中发现 function 入口点(在 Run 方法中由 FunctionName 注释)。 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.因此,您只能将所有可重用代码外部化为单独的 nuget,但仍需要为主机中的每个 function 定义入口点。 The function body might then be just bare minimum wrapper calling your reusable assets, but needs to be present in host. function 主体可能只是调用可重用资产的最小包装器,但需要存在于主机中。 Would you mind to share a bit more about the scenario you are trying to solve?您介意分享更多有关您要解决的方案的信息吗?

EDIT: Thanks @Nsevens for trying this out.编辑:感谢@Nsevens 尝试这个。 <FunctionsInDependencies>true</FunctionsInDependencies> in the.csproj would load functions from dependencies. .csproj 中的<FunctionsInDependencies>true</FunctionsInDependencies>将从依赖项中加载函数。 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.应该从主机显式调用依赖项的某些方法(可能只是一个 noop 方法),以使其成为编译器的硬依赖项。 I did not see any official documentation about this.我没有看到任何有关此的官方文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM