Templates and resources for F# Http Trigger function broken
See original GitHub issueWhere to start…
I’ve been trying for a full day to create a Azure function using F# and I’ve finally managed to do so after following many tutorials (outdated or up to date, but with bugs) and applying changes from a couple of not merged PRs and issues on different repositories.
Following this official page it is unclear what tutorial I need to follow, but after trial and error I have found out that they are all outdated.
After landing on this page I thought that finally I have landed on a single page where I have all the information I need to get started, but no there is not a single useful thing on that page to get started.
Then I started searching on the Internet for F# azure function tutorials and I landed on this page which pointed me in the direction of azure template for F# functions. Up until this point I have not heard or read anything about these templates. Upon further research I realized that that article was just a copy from this page from @aaronpowell.
Then I added the templates:
dotnet new --install Microsoft.Azure.WebJobs.ItemTemplates
dotnet new --install Microsoft.Azure.WebJobs.ProjectTemplates
Then I run this command:
dotnet new func -lang F# -o FunctionsInFSharp
Output:
The template "Azure Functions" was created successfully.
An update for template pack Microsoft.Azure.WebJobs.ProjectTemplates::3.1.1812 is available.
install command: dotnet new -i Microsoft.Azure.WebJobs.ProjectTemplates::4.0.1844-preview1
Then I run this command to add a http trigger function:
dotnet new http -lang F# --name HttpTrigger -o FunctionsInFSharp
Output:
The template "HttpTrigger" was created successfully.
Processing post-creation actions...
Description: Opens the function class file in the editor
Manual instructions:
An update for template pack Microsoft.Azure.WebJobs.ItemTemplates::3.1.1812 is available.
install command: dotnet new -i Microsoft.Azure.WebJobs.ItemTemplates::4.0.1844-preview1
Again, do I need to update or not? No clue.
Then I opened the directory with VSCode and the extension (Azure Functions) displayed this message:
Detected an Azure Functions Project in folder "fsharp-azure-functions" that may have been created outside of VS Code. Initialize for optimal use with VS Code?
I clicked yes, and I got a new directory .vscode
with some files inside. It adds the tasks for:
- build
- func host start
- clean
- clean release
- publish
They all work, except the publish
command. I have no clue what does that do.
Then I press F5 and get this message:
Failed to verify "AzureWebJobsStorage" connection specified in "local.settings.json". Is the local emulator installed and running?
I click on “Debug anyway”. (This popup keeps showing everytime I hit F5.)
Then I get these two messages:
[2021-09-14T20:51:43.340Z] Csproj not found in /home/mabasic/code/src/github.com/laravelista/fsharp-azure-functions/FunctionsInFSharp/bin/Debug/netcoreapp3.1 directory tree. Skipping user secrets file configuration.
and
[2021-09-14T20:51:45.660Z] No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).
I fix the second message with this step which is mentioned in the blog post.
I included the file HttpTrigger.fs
in FunctionsInFSharp/FunctionsInFSharp.fsproj
as mentioned in the blog post in:
<ItemGroup>
<Compile Include="HttpTrigger.fs" />
</ItemGroup>
and pressed F5 to debug the function as instructed.
Then I got this error:
Host.json file in missing. Please make sure host.json file is present at /home/mabasic/code/src/github.com/laravelista/fsharp-azure-functions/FunctionsInFSharp/bin/Debug/netcoreapp3.1
I fix this by changing this line in FunctionsInFSharp.fsproj
file:
<None Update="host.json">
to
<None Include="host.json">
and
<None Update="local.settings.json">
to
<None Include="local.settings.json">
Once again I hit F5. This time I get a warning, but the function starts correctly:
[2021-09-14T20:56:13.010Z] Csproj not found in /home/mabasic/code/src/github.com/laravelista/fsharp-azure-functions/FunctionsInFSharp/bin/Debug/netcoreapp3.1 directory tree. Skipping user secrets file configuration.
Functions:
HttpTrigger: [GET,POST] http://localhost:7071/api/HttpTrigger
The deployment worked and it seemed that all is good, but then I noticed that it is targeting netcoreapp3.1
. I wanted to use net5.0
, so I change this line in FunctionsInFSharp.fsproj
from
<TargetFramework>netcoreapp3.1</TargetFramework>
to
<TargetFramework>net5.0</TargetFramework>
Then I run dotnet restore
and run “Task clean” and “Task clean release”. After that the function builds correctly but after I deploy it (I select .NET 5 as the runtime) I get this error:
The remote runtime "dotnet-isolated" for function app "test-sample-net5" does not match your local runtime "dotnet".
Then I change this line in local.settings.json
from:
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
to
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
and then I delete the directories bin
and obj
and run “Task build” and “Task func host start” and then I get:
> Executing task: dotnet build /property:GenerateFullPaths=true /consoleloggerparameters:NoSummary <
Microsoft (R) Build Engine version 16.9.0+57a23d249 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
All projects are up-to-date for restore.
FunctionsInFSharp -> /home/mabasic/code/src/github.com/laravelista/fsharp-azure-functions/FunctionsInFSharp/bin/Debug/net5.0/FunctionsInFSharp.dll
Terminal will be reused by tasks, press any key to close it.
> Executing task: func host start <
it stalls and does nothing.
Then I’ve learned about .NET isolated process (in-process and out-of-process) here. It would seem that using dotnet-isolated
is required to use net5.0
runtime.
After checking the issues and pull requests I have found this:
- https://github.com/Choc13/az-function-fsharp-net5
- https://github.com/recumbent/fsharp-isolated
- https://github.com/landy/azurefunctions-isolated-example
- https://github.com/Azure/azure-functions-templates/pull/1090 (Changes update to include)
- https://github.com/Azure/azure-functions-templates/pull/1074 (great resource, but does not work once mirrored, maybe because it is for functions 4.0, and not 3.0. Don’t know.)
- https://github.com/Azure/azure-functions-core-tools/pull/2667 (Great hope for this PR)
- https://github.com/Azure/azure-functions-templates/issues/988
- https://github.com/Azure/azure-functions-templates/issues/986
- https://github.com/Azure/azure-functions-core-tools/issues/2549
- https://github.com/Azure/azure-functions-core-tools/issues/1963
- https://github.com/Azure/azure-functions-core-tools/issues/287
- https://github.com/Azure/azure-functions-core-tools/issues/428
- https://github.com/Azure/azure-functions-core-tools/issues/567
- https://github.com/Azure/azure-functions-core-tools/issues/2507
- https://github.com/Azure/azure-functions-core-tools/issues/1663
After a few hours of tweaking things and experimenting with packages, code, and configuration I’ve succeeded to create a working function which uses net5.0
under dotnet-isolated
runtime.
I am willing to create a PR or a starter repository for this if needed.
Can we somehow streamline this whole experience so that I can pick if I want to use net5.0
or netcoreapp3.1
and that it works correctly without me having to read issues and PR code and other people example repositories for a simple bootstrap command to work?
Do I need to add a new template for this or are going in the func new direction?
My impression now is that considering how broken this whole experience feels like, I am not sure if proceeding with F# Azure functions is a way to go for now. I got the function to work, but my next step is using CosmosDB and I am afraid of what I will find next.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:5 (2 by maintainers)
@kashimiz I’m happy to help out on some of those front, I’ve got a bunch of stuff deployed running F#.
Regarding templates - I’ve just had merged a PR that brings in templates for dotnet-isolated (#1074) as well as better support for creating F# projects using the Functions CLI (https://github.com/Azure/azure-functions-core-tools/pull/2667).
I’ve previously spoken with @craigshoemaker around F# samples on docs, and he’s agreed that one of the biggest barriers to docs is good tooling (which I’ve chipped away at recently). So, if we start getting better tooling (started with updates to the CLI and templates) then it opens to gateway for better docs, which in turn can help validate tooling approaches.
@mabasic Thank you so much for powering through this writing up this thorough explanation and resource list. This has been tremendously helpful to me working on the same thing!