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:
- .NET Core 3.0 Preview 2 SDK (3.0.100-preview-010184)
- Visual Studio 2019 (Preview 2 or later) with the ASP.NET and web development workload selected.
- The latest Blazor extension from the Visual Studio Marketplace.
-
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
withComponentBase
. - Update overrides of
SetParameters
on components to overrideSetParametersAsync
instead. - Replace
BlazorLayoutComponent
withLayoutComponentBase
- Replace
IBlazorApplicationBuilder
withIComponentsApplicationBuilder
. - Replace any using statements for
Microsoft.AspNetCore.Blazor.*
withMicrosoft.AspNetCore.Components.*
, except leaveMicrosoft.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 update
Startup.ConfigureServices
to callservices.AddMvc().AddNewtonsoftJson()
- Update the target framework to be
- 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 toapp.AddResponseCompression
to call the default overload without specifying WebAssembly or binary data as additional MIME types to compress. - In
Startup.Configure
add a call toapp.UseBlazorDebugging()
after the existing call toapp.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
withMicrosoft.AspNetCore.Components.Server
- Replace
services.AddServerSideBlazor
withservices.AddRazorComponents
andapp.UseServerSideBlazor
withapp.UseRazorComponents
. - In the
Startup.Configure
method addapp.UseStaticFiles()
just prior to callingapp.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 theStartup.ConfigureServices
method. - Add a call to
app.UseStaticFiles()
in theStartup.Configure
method prior to the call toUseMvc
. - Replace the call to
UseBlazor
withapp.UseRazorComponents<Client.Startup>()
- If you're using dependency injection to inject an
HttpClient
into your components, then you'll need to add anHttpClient
as a service in your server'sStartup.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:
Thanks for trying out Blazor!
I have to say, the timing for Blazor is very unfortunate! We are having to replace our Silverlight solution with a new application before the end of support for Sliverlight in 2021. At this time we can’t wait anymore for Blazor to be available, this pretty much means we have to switch to Javascript, even though we would have loved to stay on C# for all of our code… its a pitty!
Hi Thomas,
Server-side Blazor is now shipping with .NET Core 3.0, which will ship a stable release in Sept of this year. We also expect to have go-live release candidates for .NET Core 3.0 in July and August of this year.
Blazor for WebAssembly is also now in official preview! https://devblogs.microsoft.com/aspnet/blazor-now-in-official-preview/. It won't ship with .NET Core 3.0, but we are working on the specific roadmap for client-side Blazor which we hope to share soon. We have however...
Blazor is the future… I can’t wait for the official release of Blazor!! I have already started building a real world project.
Just some help before you spend hours on this like I did. If you are one of those people out there on a Mac trying to follow these instructions - you should know that Step 3 is impossible to complete at the current time (even if you are running Visual Studio 2019 Preview) as the Blazor extension from the Visual Studio Marketplace is not ready for the Mac yet.The team has advised that the extension...
I want to update my Solution. But i dont understand your steps.
What exactly do you mean here:
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.
I think it's a pity that this time, with a much more difficult update, you didn't bother as much with the update description and listed it only provide a short summary .
I just want to say that Blazor looks really cool, and I hope that someday it is ready for production workloads. I will be waiting 😀
I ran up the ‘default’ Razor Components solution which has a .App and a .Server project. Understandably the .Server project’s target is Core 3.0, but not so .App which is using Standard 2.0. Could someone please tell me why both projects are not targetting Core 3.0 as I’m finding that a bit confusing? Many thanks.
The .App project could also run in the browser (Mono runtime compiled to webassembly) using Blazor.
To keep the UI parts (the .App project) compatible with both server side rendering (Razor Components) and in browser rendering (Blazor) it is using .Net Standard 2.0.
A project targetting .Net Standard 2.0 can run in the classic .Net runtime, .Net Core runtime and Mono. It is the preferred project target for shared code.