3

I have an existing project, and I want to add Blazor to my project, but in all the information available on the internet, I have not found how to do that. All I find is about how to add js to blazor pages.

1
  • 1
    What kind of project? That matters a lot. Commented May 5, 2019 at 14:10

1 Answer 1

4

Let's assume that your application want to use client-side Blazor, which would be simplest form to integrate. Also I will assume that you use ASP.NET Core for simplification.

  1. You create Blazor client-side application. This application would be completely standalone and in the end would be just WASM code + .NET Dlls interpreted by Mono WASM.
  2. In the ConfigureServices of your Startup.cs in ASP.NET Core application where you want integrate Blazor add lines below
services.AddResponseCompression(opts =>
{
    opts.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(new[] { "application/octet-stream" });
});

See https://github.com/aspnet/AspNetCore/blob/master/src/Components/Blazor/Templates/src/content/BlazorHosted-CSharp/BlazorHosted-CSharp.Server/Startup.cs#L18-L22

  1. In the Configure of your Startup.cs in ASP.NET Core application where you want integrate Blazor add lines below
app.UseBlazor<BlazorAppClient.Startup>();

where BlazorAppClient.Startup is Startup class of your Blazor standalone application which you create earlier. See https://github.com/aspnet/AspNetCore/blob/master/src/Components/Blazor/Templates/src/content/BlazorHosted-CSharp/BlazorHosted-CSharp.Server/Startup.cs#L43

All of that under assumption that you use latest .NET Core 3 Preview 5 bits.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.