In early November, 2021 Azure Functions announced its GA for .NET 6 support and V4 runtime. At the same time, Azure Functions OpenAPI Extension also announced its GA, which supports all .NET Core 2.1 LTS, 3.1 LTS, .NET 5 and .NET 6. In this post, I'm going to discuss what codebase needs to be updated to support .NET 6 and the V4 runtime.
OpenAPI Extension Update
This GA package has now removed the -preview
tag. Therefore, if you want to keep the existing runtime, simply change the version to 1.0.0
(line #5). Here's the .csproj
file that you need to change if your app uses either .NET Core 2.1 or 3.1.
<Project Sdk="Microsoft.NET.Sdk"> | |
... | |
<ItemGroup> | |
<!-- .NET Core 2.1 or 3.1: In-process Worker --> | |
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.OpenApi" Version="1.0.0" /> | |
</ItemGroup> | |
... | |
</Project> |
If you've been using both .NET 5 and out-of-proc worker, also change the version to 1.0.0
(line #5).
<Project Sdk="Microsoft.NET.Sdk"> | |
... | |
<ItemGroup> | |
<!-- .NET 5: Out-of-process Worker --> | |
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.OpenApi" Version="1.0.0" /> | |
</ItemGroup> | |
... | |
</Project> |
Your existing app doesn't require any code change by updating the package version and should just work.
But, it's a different story when you upgrade the function runtime from V3 to V4. In that case, you also need to change another part of the .csproj
file. In addition to that, You must upgrade your Azure Functions Core Tools to V4 for your local development.
Migrating .NET Core 3.1 to .NET 6
Open the .csproj
file and find the TargetFramework
element. Then change its value from netcoreapp3.1
to net6.0
. After that, look for the AzureFunctionsVersion
element and change the value from v3
to v4
(line #4-5, 8-9).
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<!-- Change these values --> | |
<TargetFramework>netcoreapp3.1</TargetFramework> | |
<AzureFunctionsVersion>v3</AzureFunctionsVersion> | |
<!-- To these values --> | |
<TargetFramework>net6.0</TargetFramework> | |
<AzureFunctionsVersion>v4</AzureFunctionsVersion> | |
... | |
</PropertyGroup> | |
... | |
</Project> |
Once it's done, rebuild the entire solution and run the app. It should just work fine.
NOTE: If you use .NET Core 2.1, then change the value of the
TargetFramework
element fromnetcoreapp2.1
tonet6.0
.
Migrating .NET 5 to .NET 6
The same rules apply. Open the .csproj
file and find the TargetFramework
element. Then change its value from net5.0
to net6.0
. After that, look for the AzureFunctionsVersion
element and change the value from v3
to v4
(line #4-5, 8-9).
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<!-- Change these values --> | |
<TargetFramework>net5.0</TargetFramework> | |
<AzureFunctionsVersion>v3</AzureFunctionsVersion> | |
<!-- To these values --> | |
<TargetFramework>net6.0</TargetFramework> | |
<AzureFunctionsVersion>v4</AzureFunctionsVersion> | |
... | |
</PropertyGroup> | |
... | |
</Project> |
Once it's done, rebuild the entire solution and run the app. It should just work fine.
Did I change any codebase? No. All you need to do is to change the extension package version, target framework version and runtime version. Then, it should just work. Unless one of the packages you're referencing has a dependency on .NET Core 2.1/3.1 or .NET 5, you'll be able to enjoy the latest version of the .NET and OpenAPI extension.