How to migrate Blazor Webassembly to .NET 5
.NET 5 is out today! It’s a big milestone and comes with a huge list of improvements. I’ve been working a bit with Blazor lately, trying to brush up my gamedev skills again. So I took the chance and decided to upgrade my little pet project to the latest version 🙂
The first thing to do is to install or update Visual Studio 2019 to version 16.8.0. For those interested, the release notes are available here. In case you’re using a different IDE (or you’re on Linux/Mac), you can directly download the .NET 5 SDK instead.
Once you’ve done installing, fire up your Blazor project and open the .csproj file. We’re going to change few little things:
- At the very top, update the SDK from
<em>Microsoft.NET.Sdk.Web</em>
to<em>Microsoft.NET.Sdk.BlazorWebAssembly</em>
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
- Set the TargetFramework to net5.0
<PropertyGroup> <TargetFramework>net5.0</TargetFramework> </PropertyGroup>
In case you have it, remove the package reference to Microsoft.AspNetCore.Components.WebAssembly.Build
Update your Nuget dependencies
Now make sure you Clean your entire solution, otherwise the build engine won’t be able to re-generate all the required files with the updated framework.
Enjoy!