How do I check the framework version?

Platform: Blazor| Category: General

Using C# conditional preprocessor directives and predefined constants, you can check the Blazor target framework version. For example, if the framework targets .NET 6.0, or latest version the code is compiled only in that specified condition. Follow these steps to check the Blazor target framework version.

[Index.razor]

@page "/" 
<h1>@blazorVersion</h1> 

@code { 
    private string? blazorVersion { get; set; } 
    protected override void OnInitialized () 
    { 
#if NET6_0 
        blazorVersion = "Blazor App version is .NET6.0"; 
#elif NET5_0 
    blazorVersion = "Blazor App version is .NET5.0"; 
#elif NETCOREAPP3_1 
    blazorVersion = "Blazor App version is netcoreapp3.1"; 
#endif 
    } 
} 

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.