Migrating to Azure Function v3 in 5 minutes

-

Azure Function v3 is now officially ready for production! And as a .NET developer I’m happy that I finally can use this new version. It provides netcore 3.x support. You can start using the latest improvements from Netcore and start using C# 8 syntax! It is time to upgrade from version 2 azure functions to this new version. I’ve also added an explanation how to upgrade you azure devops build pipeline to be able to build netcore 3. It is easy and only takes 5 minutes.

Visual Studio 2019 Upgrade

Azure functions version 3 requires some upgrades being done to your visual studio. It is required to upgrade to version 16.4 or higher to be able to work with azure functions v3. This version check can be done in visual studio by right-clicking on the red icon on the bottom right.

Amongst other things the upgrade of Visual Studio installs the Azure Function local runtime for version 3.

Upgrading your Azure functions csproj file

What also need to be done is to upgrade the application to netcore 3.1. It also requires the Azure Function Runtime Version 3.0. This can be done by editing the csproj file.

After the .csproj file is edited the project is build as netcore 3.1. However, because the application was upgraded from a netcore 2.1 version, there are some compiler errors.

This can easily be resolved. Upgrade the Microsoft.NET.Sdk.Function nuget package to version 3.x.

Visual Studio should now be able to run your azure function again when executing locally.

Upgrading the Azure ARM template

Now the Azure Function app is working with the v3 function runtime and netcore 3.x. What still needs to be done is to modify the ARM template so it will deploy the azure function correctly. This can be done by modifying the FUNCTION_EXTENSIONS_VERSION setting in the ARM template.

Upgrading the Azure Devops pipeline to build correctly

Once there is a correct ARM template we need to deploy it using Azure devops. Your Azure Devops pipeline should be be able to build and deploy correctly. But if any build problem occur it could be that the following task prevents using the latest dotnet version. This task can be removed.

If the dotnet-ef command was used to generate sql upgrade scripts it will now fail because as of netcore 3.1. The dotnet-ef tool is not packaged with dotnet anymore by default.

If the error shown above occurs there is a dotnet-ef issue. Add the following task prior to executing the dotnet-ef command.

 – scriptdotnet tool install –global dotnet-ef

The build should now succeed when the devops pipeline is run. If it also automated the azure function deployment into azure the following warning will be shown in Azure.

It can be ignored unless problems occur. Microsoft gives this warning as possible csproj settings could be broken due to the upgrade. Their advice is to create a new function app project. Move the sources into that project. This way it is ensured the csproj file is correct.

Summary

By following this guide you have now upgraded to the latest version of azure function. You are now ready to release your Azure function V3 to production!