Reason to use Azure Functions 3.0
The Azure Functions 3.0 go-live release is available since December 09, 2019. A major benefit of this release is that you can write Azure Functions targeting .NET Core 3.1. Why is this important?
Every Microsoft product has a lifecycle that begins when a product is released and ends when it’s no longer supported. The same is true for .NET Core. Right now, there are only two .NET Core versions with Long Term Support (LTS) available:
Version | Original Release Date | End of Support | Support Level |
.NET Core 3.1 | December 3, 2019 | TBD | LTS |
.NET Core 3.0 | September 23, 2019 | March 3, 2020 | Maintenance |
.NET Core 2.2 | December 4, 2018 | December 23, 2019 | Maintenance |
.NET Core 2.1 | May 30, 2018 | August 21, 2021 | LTS |
.NET Core 2.0 | August 14, 2017 | October 1, 2018 | EOL |
.NET Core 1.1 | November 16, 2016 | June 27 2019 | EOL |
.NET Core 1.0 | June 27, 2016 | June 27 2019 | EOL |
LTS releases are supported for three years after the initial release. So this means we can either target .NET Core 3.1 or .NET Core 2.1 within our Azure Functions to leverage LTS. Right? Wrong!
Let’s take a look at the Azure Functions runtime versions overview:
Runtime version | .NET version |
3.x | .NET Core 3.x |
2.x | .NET Core 2.2 |
1.x | .NET Framework 4.63 |
As you can see in the table, the Azure Functions Runtime 2.x uses .NET Core 2.2 which support ends on December 23, 2019. So the only real option we have if we need LTS for our SDK and Runtime, is to use .NET Core 3.1 with Azure Functions 3.0.
Update client tools
Upgrade the .NET Core SDK
Before we can migrate our projects to the newer versions, we have to install the last recent .NET Core 3.1 SDK. To find out which .NET Core version we have installed, we can run:
dotnet --version
This is how my output looks like before the upgrade:
You can skip the step if the output of the above command equals 3.1.100. If not, you can download the SDK here.
Upgrade Azure Functions Core Tools
On Windows, you currently have to install the last recent runtime using npm:
npm install -g azure-functions-core-tools@3
Note: If you have installed a previous version using chocolatey, you can uninstall it using:
choco uninstall azure-functions-core-tools
Migrate Azure Functions 2.x to 3.1
Update the project file
Within our Azure Function project file (*.csproj) we have to change three things:
- Change the TargetFramework to
netcoreapp3.1
- The AzureFunctionsVersion to
v3
- The Microsoft.NET.Sdk.Functions package reference to version
3.0.1
This is how the diff of my migration looks like:
Update Azure Function Application settings
Azure Functions lets you target a specific version of the runtime by using the FUNCTIONS_EXTENSION_VERSION
application setting. This ensures that the function app is kept on the specified major version until you explicitly choose to upgrade to a new version. In our case, we have to set the value to ~3
:
Note: Please ensure to update this application setting within your Infrastructure as Code (IAC) components (e. g. ARM template).
Update Azure DevOps Pipeline
If you are using the DotNetCoreCLI@2
task to build your Azure Function Projects, you build will probably fail with an error message similar to this:
/usr/share/dotnet/sdk/3.0.101/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(127,5): error NETSDK1045: The current .NET SDK does not support targeting .NET Core 3.1. Either target .NET Core 3.0 or lower, or use a version of the .NET SDK that supports .NET Core 3.1.
You get this error because the Microsoft-hosted agents for Azure DevOps don’t have the new SDK yet (see: included Software).
As a workaround, you can use the UseDotNet@2 task to acquire a specific version of .NET Core within your build:
- task: UseDotNet@2 displayName: 'Acquire .NET Core SDK' inputs: packageType: sdk version: 3.1.x
This is it. Please note that we don’t have to upgrade the version within the hosts.json since its schema is different than the version of the Azure Function Runtime.