将预编译的 .NET 代码作为 Azure 函数执行 [英] Execute pre-compiled .NET code as Azure Function

查看:26
本文介绍了将预编译的 .NET 代码作为 Azure 函数执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何上传预编译的 .NET 程序集(-ies)并作为 Azure Functions 执行我的代码?

How do I upload a pre-compiled .NET assembly(-ies) and execute my code as Azure Functions?

我正在寻找一种方法来运行一些复杂的域逻辑,这些逻辑包含在自定义程序集中并被单元测试等覆盖.

I'm looking for a way to run some complex domain logic, which is contained inside custom assemblies and is covered by unit tests etc.

此代码有哪些限制?例如.访问远程数据存储、网络等

What kind of limitations for this code are there? E.g. access remote data stores, networking etc.

推荐答案

更新:下面的答案仍然正确(仍然有效),但是现在也有对预编译的一流支持功能.请参阅维基页面了解更多信息.

Update: The below answer is still correct (still works), however there is now also first class support for precompiled functions. See the wiki page for more information on that.

文档(此处链接) 描述了如何使用 #r 语法从 C# 函数中引用外部库和 Nuget 包,例如:

The documentation (link here) describes how you can reference external libraries and Nuget packages from a C# Function using the #r syntax, e.g:

#r "System.Web.Http"

using System.Net;
using System.Net.Http;
using System.Threading.Tasks;

public static Task<HttpResponseMessage> Run(HttpRequestMessage req)

有关此的其他详细信息可以在this所以发帖.

Additional details on this can be seen in this SO post.

您还可以部署自定义可执行文件并从您的 Azure Functions 调用它们.例如,如果您从 Windows BAT 模板开始,您可以使用它来调用一个 exe.这是我们存储库中的示例,显示图像调整大小示例.在此示例中,我们有一个 BAT 脚本,每当新图像上传到 blob 容器时都会触发该脚本,该脚本调用 Resizer.exe 工具来调整大小:

You can also deploy custom executables and call them from your Azure Functions. For example, if you start from the Windows BAT template, you can use that to call out to an exe. Here's a sample of this in our repo, showing an image resize example. In this sample, we have a BAT script that is triggered whenever a new image is uploaded to a blob container, and the script calls out to a Resizer.exe tool to do the resize:

.ResizerResizer.exe %original% %resized% 200

关于限制,所有 Azure Functions 代码都在 应用服务沙箱中运行,其限制在这里.

Regarding limitations, all Azure Functions code runs in the App Service sandbox whose limitations are described here.

这篇关于将预编译的 .NET 代码作为 Azure 函数执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆