Execute pre-compiled .NET code as Azure Function

2020-01-31 06:57发布

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.

3条回答
时光不老,我们不散
2楼-- · 2020-01-31 07:34

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.

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)

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

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:

.\Resizer\Resizer.exe %original% %resized% 200

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

查看更多
Melony?
3楼-- · 2020-01-31 07:39

To run a pre-compiled .NET assembly in an Azure Function, it's possible to upload a custom dll by FTP in the function root folder (within a bin folder) and then use #r to reference it from the azure function code.

Here is an example, a dll named "WorkOnImages.dll" is uploaded in an azure in azure function folder :

import dll in azure function

Then the dll is referenced in the azure function :

include dll

Here is the source blog post

查看更多
贪生不怕死
4楼-- · 2020-01-31 08:00

Discouraged by the lack of Azure Function tooling support for VS2017, incompatibility with Azure SDK 3.0, I was about to throw in the towel for Functions and fallback to an approach using VS2017 and WebJobs SDK.

Then announced on March 16th, 2017, the easiest approach is documented here in an excellent blog post by Microsoft's Donna Malayeri.

It does everything I could want - true intellisense, debugging capabilities. It's been great and I wouldn't look back.

查看更多
登录 后发表回答