company_banner

Blazor 0.8.0 experimental release now available

    Blazor 0.8.0 is now available! This release updates Blazor to use Razor Components in .NET Core 3.0 and adds some critical bug fixes.


    Get Blazor 0.8.0


    To get started with Blazor 0.8.0 install the following:


    1. .NET Core 3.0 Preview 2 SDK (3.0.100-preview-010184)
    2. Visual Studio 2019 (Preview 2 or later) with the ASP.NET and web development workload selected.
    3. The latest Blazor extension from the Visual Studio Marketplace.
    4. The Blazor templates on the command-line:


      dotnet new -i Microsoft.AspNetCore.Blazor.Templates::0.8.0-preview-19104-04

    You can find getting started instructions, docs, and tutorials for Blazor at https://blazor.net.


    Upgrade to Blazor 0.8.0


    To upgrade your existing Blazor apps to Blazor 0.8.0 first make sure you've installed the prerequisites listed above.


    To upgrade a standalone Blazor 0.7.0 project to 0.8.0:


    • Update the Blazor packages and .NET CLI tool references to 0.8.0-preview-19104-04.
    • Replace any package reference to Microsoft.AspNetCore.Blazor.Browser with a reference to Microsoft.AspNetCore.Blazor.
    • Replace BlazorComponent with ComponentBase.
    • Update overrides of SetParameters on components to override SetParametersAsync instead.
    • Replace BlazorLayoutComponent with LayoutComponentBase
    • Replace IBlazorApplicationBuilder with IComponentsApplicationBuilder.
    • Replace any using statements for Microsoft.AspNetCore.Blazor.* with Microsoft.AspNetCore.Components.*, except leave Microsoft.AspNetCore.Blazor.Hosting in Program.cs
    • In index.html update the script reference to reference components.webassembly.js instead of blazor.webassembly.js

    To upgrade an ASP.NET Core hosted Blazor app to 0.8.0:


    • Update the client-side Blazor project as described previously.
    • Update the ASP.NET Core app hosting the Blazor app to .NET Core 3.0 by following the migrations steps in the ASP.NET Core docs.
      • Update the target framework to be netcoreapp3.0
      • Remove any package reference to Microsoft.AspNetCore.App or Microsoft.AspNetCore.All
      • Upgrade any non-Blazor Microsoft.AspNetCore.* package references to version 3.0.0-preview-19075-0444
      • Remove any package reference to Microsoft.AspNetCore.Razor.Design
      • To enable JSON support, add a package reference to Microsoft.AspNetCore.Mvc.NewtonsoftJson and updateStartup.ConfigureServices to call services.AddMvc().AddNewtonsoftJson()
    • Upgrade the Microsoft.AspNetCore.Blazor.Server package reference to 0.8.0-preview-19104-04
    • Add a package reference to Microsoft.AspNetCore.Components.Server
    • In Startup.ConfigureServices simplify any call to app.AddResponseCompression to call the default overload without specifying WebAssembly or binary data as additional MIME types to compress.
    • In Startup.Configure add a call to app.UseBlazorDebugging() after the existing call to app.UseBlazor<App.Startup>()
    • Remove any unnecessary use of the Microsoft.AspNetCore.Blazor.Server namespace.

    To upgrade a Blazor class library to 0.8.0:


    • Replace the package references to Microsoft.AspNetCore.Blazor.Browser and Microsoft.AspNetCore.Blazor.Build with references to Microsoft.AspNetCore.Components.Browser and Microsoft.AspNetCore.Components.Build and update the versions to 3.0.0-preview-19075-0444.
    • In the project file for the library change the project SDK from «Microsoft.NET.Sdk.Web» to «Microsoft.NET.Sdk.Razor».

    Server-side Blazor is now ASP.NET Core Razor Components in .NET Core 3.0


    As was recently announced, server-side Blazor is now shipping as ASP.NET Core Razor Components in .NET Core 3.0. We've integrated the Blazor component model into ASP.NET Core 3.0 and renamed it to Razor Components. Blazor 0.8.0 is now built on Razor Components and enables you to host Razor Components in the browser on WebAssembly.


    Upgrade a server-side Blazor project to ASP.NET Core Razor Components in .NET Core 3.0


    If you've been working with server-side Blazor, we recommend upgrading to use ASP.NET Core Razor Components in .NET Core 3.0.


    To upgrade a server-side Blazor app to ASP.NET Core Razor Components:


    • Update the client-side Blazor project as described previously, except replace the script reference to blazor.server.js with components.server.js
    • Update the ASP.NET Core app hosting the Razor Components to .NET Core 3.0 as described previously.
    • In the server project:
      • Upgrade the Microsoft.AspNetCore.Blazor.Server package reference to 0.8.0-preview-19104-04
      • Add a package reference to Microsoft.AspNetCore.Components.Server version 3.0.0-preview-19075-0444
      • Replace the using statement for Microsoft.AspNetCore.Blazor.Server with Microsoft.AspNetCore.Components.Server
      • Replace services.AddServerSideBlazor with services.AddRazorComponents and app.UseServerSideBlazor with app.UseRazorComponents.
      • In the Startup.Configure method add app.UseStaticFiles() just prior to calling app.UseRazorComponents.
      • Move the wwwroot folder from the Blazor app project to the ASP.NET Core server project

    Switching between ASP.NET Core Razor Components and client-side Blazor


    Sometimes it's convenient to be able to switch between running your Razor Components on the server (ASP.NET Core Razor Components) and on the client (Blazor). For example, you might run on the server during development so that you can easily debug, but then publish your app to run on the client.


    To update an ASP.NET Core hosted Blazor app so that it can be run as an ASP.NET Core Razor Components app:


    • Move the wwwroot folder from the client-side Blazor project to the ASP.NET Core server project.
    • In the server project:
      • Update the script tag in index.html to point to components.server.js instead of components.webassembly.js.
      • Add a call to services.AddRazorComponents<Client.Startup>() in the Startup.ConfigureServices method.
      • Add a call to app.UseStaticFiles() in the Startup.Configure method prior to the call to UseMvc.
      • Replace the call to UseBlazor with app.UseRazorComponents<Client.Startup>()

    • If you're using dependency injection to inject an HttpClient into your components, then you'll need to add an HttpClient as a service in your server's Startup.ConfigureServices method.

    Tooling for Blazor projects is now included with Visual Studio 2019


    Previously to get tooling support for Blazor projects you needed to install the Blazor extension for Visual Studio. Starting with Visual Studio 2019 Preview 2, tooling support for Razor Components (and hence Blazor apps) is already included without having to install anything else. The Blazor extension is now only needed to install the Blazor project templates in Visual Studio.


    Runtime improvements


    Blazor 0.8.0 includes some .NET runtime improvements like improved runtime performance on Chrome and an improved IL linker. In our performance benchmarks, Blazor 0.8.0 performance on Chrome is now about 25% faster. You can now also reference existing libraries like Json.NET from a Blazor app without any additional linker configuration:


    @functions {
        WeatherForecast[] forecasts;
    
        protected override async Task OnInitAsync()
        {
            var json = await Http.GetStringAsync("api/SampleData/WeatherForecasts");
            forecasts = Newtonsoft.Json.JsonConvert.DeserializeObject<WeatherForecast[]>(json);
        }
    }

    Known issues


    There are a couple of known issues with this release that you may run into:


    • «It was not possible to find any compatible framework version. The specified framework 'Microsoft.NETCore.App', version '2.0.0' was not found.»: You may see this error when building a Blazor app because the IL linker currently requires .NET Core 2.x to run. To work around this issue, either install .NET Core 2.2 or disable IL linking by setting the <BlazorLinkOnBuild>false</BlazorLinkOnBuild> property in your project file.
    • «Unable to generate deps.json, it may have been already generated.»: You may see this error when running a standalone Blazor app and you haven't yet restored packages for any .NET Core apps. To workaround this issue create any .NET Core app (ex dotnet new console) and then rerun the Blazor app.

    These issues will be addressed in a future Blazor update.


    Future updates


    This release of Blazor was primarily focused on first integrating Razor Components into ASP.NET Core 3.0 and then rebuilding Blazor on top of that. Going forward, we plan to ship Blazor updates with each .NET Core 3.0 update.


    Blazor, and support for running Razor Components on WebAssembly in the browser, won't ship with .NET Core 3.0, but we continue to work towards shipping Blazor some later date.


    Give feedback


    We hope you enjoy this latest preview release of Blazor. As with previous releases, your feedback is important to us. If you run into issues or have questions while trying out Blazor, file issues on GitHub. You can also chat with us and the Blazor community on Gitter if you get stuck or to share how Blazor is working for you. After you've tried out Blazor for a while please let us know what you think by taking our in-product survey. Click the survey link shown on the app home page when running one of the Blazor project templates:


    Blazor survey


    Thanks for trying out Blazor!

    Microsoft
    388.52
    Microsoft — мировой лидер в области ПО и ИТ-услуг
    Share post

    Comments 0

    Only users with full accounts can post comments. Log in, please.