Create a new .NET 5 Blazor Project
When Visual Studio 2019 creates a new Blazor app it defaults to .NET Standard 2.1. A few months ago .NET 5 was released, and upgrading Blazor apps to use .NET 5 has many strong performance improvements. I’m sure a Visual Studio update will soon make this easier, but for now to create a new .NET Blazor app running .NET 5 I use these steps:
- Create a new .NET core 3.1 Blazor App
- Edit the csproj file
- Change SDK from
Microsoft.NET.Sdk.WebtoMicrosoft.NET.Sdk.BlazorWebAssembly - Remove
RazorLangVersion - Update
TargetFrameworkfromnetstandard2.1tonet5.0 - Remove the
Microsoft.AspNetCore.Components.WebAssembly.Buildpackage reference
- Change SDK from
- update all NuGet packages to their latest versions
Extensive details can be found on Microsoft’s official Migrate from ASP.NET Core 3.1 to 5.0 documentation page, but I find this short list of steps easier to refer to.
Download a New .NET 5.0.1 Blazor App
Here is a new project running .NET 5.0.1 with Bootstrap 5.0 alpha:
To change the project name/namespace:
- Rename the
.slnand.csprojfiles - Update the
.slnfile in a text editor to match the new filenames - Update the namespace in
Program.cs - Update the namespaces in
_Imports.razor