-
Notifications
You must be signed in to change notification settings - Fork 458
Precompiled functions
Fabio Cavalcante edited this page Jan 3, 2017
·
6 revisions
Azure Functions supports pre-compiled functions, which enables the use of .NET assemblies containing the function implementation, bypassing the dynamic compilation process.
In order to use pre-compiled functions, your function.json
file must have the scriptFile
and entryPoint
properties set, pointing to the assembly file and fully qualified method name, respectively:
{
"scriptFile": "PreCompiledFunctionSample.dll",
"entryPoint": "PreCompiledFunctionSample.MyFunction.Run",
"bindings": [
{
"authLevel": "function",
"name": "req",
"type": "httpTrigger",
"direction": "in"
},
{
"name": "$return",
"type": "http",
"direction": "out"
}
],
"disabled": false
}
using System.Net;
using System.Linq;
using System.Threading.Tasks;
using System.Net.Http;
namespace PreCompiledFunctionSample
{
public class MyFunction
{
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req)
{
// parse query parameter
string name = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
.Value;
// Get request body
dynamic data = await req.Content.ReadAsAsync<object>();
// Set name to query string or body data
name = name ?? data?.name;
return name == null
? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
: req.CreateResponse(HttpStatusCode.OK, "Hello " + name);
}
}
}
With this approach, functions can be developed as a regular class library, using any .NET language. For the above sample, the function folder contained the function.json
and the assembly file, PreCompiledFunctionSample.dll
A sample project with the above function is available here
- Configuration Settings
- function.json
- host.json
- host.json (v2)
- Http Functions
- Function Runtime Versioning
- Official Functions developers guide
- Host Health Monitor
- Managing Connections
- Renaming a Function
- Retrieving information about the currently running function
- Site Extension Resolution
- Linux Consumption Regions
- Using LinuxFxVersion for Linux Function apps
- Out-of-proc Cancellation Tokens
- Assembly Resolution in Azure Functions
- ILogger
- Precompiled functions
- Official Functions C# developer reference
- Contributor Onboarding
- Development Process
- Deploying the Functions runtime as a private site extension
- Authoring & Testing Language Extensions
- Bindings in out-of-proc
- Language Extensibility
- Worker Capabilities
- Investigating and reporting issues with timer triggered functions not firing
- Sharing Your Function App name privately
- Azure Functions CLI release notes [moved here]
- Function App Zipped Deployment [deprecated]