Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute pre-compiled .NET code as Azure Function

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.

like image 610
Mikhail Shilkov Avatar asked Apr 05 '16 20:04

Mikhail Shilkov


3 Answers

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.

like image 187
mathewc Avatar answered Nov 03 '22 15:11

mathewc


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

like image 3
Thibaut Ranise Avatar answered Nov 03 '22 16:11

Thibaut Ranise


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.

like image 3
flyte Avatar answered Nov 03 '22 14:11

flyte