For me, I had to go through converting a C# function project into F#:
- Create C# Azure Function Project
- rename
.csproj to .fsproj
- Edit the
.fsproj file and make sure the following items are in there:
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.24" />
</ItemGroup>
<ItemGroup>
<Compile Include="Function1.fs" />
<Content Include="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</Content>
</ItemGroup>
Make sure you set host.json and local.settings.json to <Content... instead of <None... so it copies it to the output file.
- Make sure you have the
Microsoft.NET.Sdk.Functions installed
- Your
Function1.fs file should look something like that (for an HttpTrigger)
namespace FunctionApp1
open System
open Microsoft.Azure.WebJobs
open Microsoft.Azure.WebJobs.Host
open System;
open System.IO;
open System.Threading.Tasks;
open Microsoft.AspNetCore.Mvc;
open Microsoft.Azure.WebJobs;
open Microsoft.Azure.WebJobs.Extensions.Http;
open Microsoft.AspNetCore.Http;
open Microsoft.Extensions.Logging;
module Function1 =
[<FunctionName("Function1")>]
let Run ([<HttpTrigger(AuthorizationLevel.Function, [|"post"|])>] req: HttpRequest) (log: ILogger) =
async {
return "some result"
}
|> Async.StartAsTask
- Now you are ready to deploy. Just right click on the project and click
Publish...
- Select
Azure Function App and follow the instructions. Make sure to select Run from pakcage file.
