If you think creating a project for Azure Functions in Visual Studio 2019, it is easy, I have the bad news for you!
Easy scenario. You want to create a simple Azure Function project with F# using Visual Studio 2019. Easy, right? First, launch Visual Studio 2019 and select “Create a new project“
![Visual Studio 2019 Start page](https://i0.wp.com/puresourcecode.com/wp-content/uploads/2020/04/image-13.png?resize=640%2C425&ssl=1)
Then, you can create new project with the wizard. For example, if you select from the dropdown “All languages” F# and from “All platforms” Azure, surprise surprise…
![Visual Studio 2019 - Create a new project](https://i0.wp.com/puresourcecode.com/wp-content/uploads/2020/04/image-15.png?resize=640%2C425&ssl=1)
You can’t! There is no option for that. My problem is that I have to create a solution for Azure Functions in F#.
![Visual Studio 2019 - Create a new project for Azure Function and F#](https://i0.wp.com/puresourcecode.com/wp-content/uploads/2020/04/image-16.png?resize=640%2C425&ssl=1)
Depressing, I found a workaround that I want to share with you. Hopefully, you can give me a better solution.
Create a new solution in C# for Azure Functions.
![Visual Studio 2019 and Azure Functions in C#](https://i0.wp.com/puresourcecode.com/wp-content/uploads/2020/04/image-17.png?resize=640%2C425&ssl=1)
Press Next.
![Visual Studio 2019: configure your new project](https://i0.wp.com/puresourcecode.com/wp-content/uploads/2020/04/image-18.png?resize=640%2C425&ssl=1)
Select where you want to create your project and then press Next.
![Visual Studio 2019: create a new Azure Functions Application](https://i0.wp.com/puresourcecode.com/wp-content/uploads/2020/04/image-19.png?resize=640%2C444&ssl=1)
Http Trigger is ok for this example; we have time to complicate the function later. Press Create and then you have you C# project in a solution! Run the project to be sure it is working fine.
![Azure Function up and running](https://i0.wp.com/puresourcecode.com/wp-content/uploads/2020/04/image-22.png?resize=640%2C505&ssl=1)
Done! Oh, wait, F#?
This is the funny part. Follow my simple instructions:
- close Visual Studio
- rename
.csproj
to.fsproj
- open the solution file and replace
.csproj
to.fsproj
- edit the
.fsproj
file and make sure the following items are in there for Azure Functions v3:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
<RootNamespace>vspan_aBillity</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.3" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
Open this solution with Visual Studio again. Now, the solution is in F#. You can add a new Azure Function in F#.
![Visual Studio 2019: add new item](https://i0.wp.com/puresourcecode.com/wp-content/uploads/2020/04/image-23.png?resize=640%2C444&ssl=1)
Replace the content of the new file with this one:
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 GetOrganizations =
[<FunctionName("GetOrganizations")>]
let Run ([<HttpTrigger(AuthorizationLevel.Function, [|"get"|])>] req: HttpRequest) (log: ILogger) =
async {
return "some result"
}
|> Async.StartAsTask
Play the project. The function is working and then you can browse your function!
![Azure Function in F# is working](https://i0.wp.com/puresourcecode.com/wp-content/uploads/2020/04/image-25.png?resize=640%2C335&ssl=1)
![Call the function with your browser](https://i0.wp.com/puresourcecode.com/wp-content/uploads/2020/04/image-24.png?resize=640%2C268&ssl=1)
You find this code on my Github. Also, if you want to know more about what Visual Studio can do for you, I recommend to read my article about digital transformation.
5 thoughts on “Create a project for Azure Function in F# and Visual Studio 2019”