-
Notifications
You must be signed in to change notification settings - Fork 442
Precompiled functions
Azure Functions supports precompiled functions, which enables the use of .NET assemblies containing the function implementation, bypassing the dynamic compilation process.
In order to use precompiled 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
}
NOTE: You can deploy your assembly to other locations and use a relative path from the function folder in your
scriptFile
path (e.g...\\bin\\PreCompiledFunctionSample.dll
)
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
Here are some sample projects:
- 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]