I’m starting to work on a new project in which I’m going to use Azure Functions v2 for a simple API backend.
Well, naturally I decided to go with F#, which kind of worked in v1. And after all, it’s a CLR language so there’s no reason it shouldn’t work in v2 like C# does.
But unfortunately there’s no templates available, so getting started seems to be a bit trickier.
Creating an F# Functions Application
To create a F# Functions Application the easiest approach is to follow the Visual Studio Code instructions to get the extensions installed.
Once VS Code is ready to go we’ll create a new New Functions Project choosing C# as the language.
Now comes the tricky part, rename your
csproj file to
fsproj and add a reference to
And you’re done!
Ok, it wasn’t really that tricky was it! Since it’s all on the CLR and it’s a .NET Core application the
dotnet cli tools will just work! You’ll even get debugging support from within VS Code of your F# Functions.
Now you’re ready to create a function with F#!
Here’s a basic HTTP trigger:
Be aware that if you’re doing anything with
async you’ll need to convert it to
Task<'T> for the return as the Functions host expects the C# Task API for async, not F#’s Async workflows 😦.
There’s a minor caveat to this whole thing, because the VS Code extension doesn’t understand F# you can’t use it to add new functions to your project, you have to manually do it, and you then have to know what NuGet packages that you require are going to be. I find it easy enough to just have another VS Code window open and create a C# one if I need to look up types and their packages.
You’ll also find that the
.vscode/settings.json file contains
"azureFunctions.projectLanguage": "C#". You can change that to
F# if you want, but it’ll give you a warning because the extension doesn’t understand it. I leave it as C# because it doesn’t bother me.
While the tooling might not be there, creating an Azure Function with F# really isn’t that big a deal.