Using C# conditional preprocessor directives and predefined constants, you can check the Blazor target framework version. For example, if the framework targets .NET 5.0, the code is compiled only in that specified condition. Follow these steps to check the Blazor target framework version.
[Index.razor]
@code {
private string blazorVersion { get; set; }
protected override void OnInitialized()
{
#if NET5_0
blazorVersion = "Blazor App version is .NET5.0";
#elif NETCOREAPP3_1
blazorVersion = "Blazor App version is netcoreapp3.1";
#endif
}
}