Langsung ke konten
Skillpedia
Website & UI (frontend)5.8k ยท #14559

convert-blazor-server-to-webapp

Fungsinya

Skill ini mengubah aplikasi Blazor Server lama ke model Blazor Web App yang lebih baru di .NET 8 atau yang lebih baru. Skill ini untuk tim .NET yang memiliki aplikasi Blazor Server lama dan ingin pindah ke model hosting terkini.

Kapan dipakai

  • โœ“Saat aplikasi Blazor Server Anda berjalan di .NET 6 atau .NET 7 dan perlu pindah ke .NET 8 ke atas.
  • โœ“Saat aplikasi Anda masih memakai pengaturan halaman host dan hub Blazor Server yang lama.
  • โœ“Saat Anda ingin fitur Blazor Web App yang baru sambil tetap memakai rendering server interaktif.

Link skill

https://github.com/dotnet/skills/blob/main/plugins/dotnet-aspnetcore/skills/convert-blazor-server-to-webapp/SKILL.md

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/dotnet/skills/blob/main/plugins/dotnet-aspnetcore/skills/convert-blazor-server-to-webapp/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit โ†’

Contoh permintaan ke AI

โ€œUbah aplikasi Blazor Server .NET 7 saya menjadi Blazor Web App di .NET 8 dan pertahankan sifat interaktifnya.โ€

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Agent memperbarui pengaturan hosting, mengganti halaman host lama dengan komponen root, memperbarui skrip dan layanan, dan mempertahankan rendering server interaktif agar perilakunya tetap sama.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.

Convert Blazor Server App to Blazor Web App

This skill helps an agent convert a pre-.NET 8 Blazor Server app into a .NET 8+ Blazor Web App. The old hosting model uses AddServerSideBlazor/MapBlazorHub with a _Host.cshtml Razor Page as the entry point. The new Blazor Web App model uses AddRazorComponents/MapRazorComponents with an App.razor root component, enabling per-component render modes, enhanced navigation, streaming rendering, and other .NET 8+ features. The converted app uses InteractiveServer render mode to preserve existing interactive behavior.

When to Use

  • Migrating a Blazor Server app from .NET 6 or .NET 7 to .NET 8+
  • App currently uses AddServerSideBlazor() and MapBlazorHub() in Program.cs (or Startup.cs)
  • App uses Pages/_Host.cshtml (or _Host.razor) as the host page with Component Tag Helpers
  • Want to adopt new Blazor Web App features while keeping interactive server rendering

When Not to Use

  • The app already uses AddRazorComponents and MapRazorComponents. It is already a Blazor Web App โ€” no conversion is needed. Stop here and tell the user the app is already using the Blazor Web App model.
  • Blazor WebAssembly or hosted Blazor WebAssembly app โ€” these have a different migration path
  • The app should stay on the legacy Blazor Server hosting model (just update TFM and packages)
  • The app targets .NET Framework โ€” it must be migrated to .NET first

Inputs

Input Required Description
Blazor Server project Yes The .csproj and source files of the Blazor Server app
Target framework Yes .NET 8 or later (e.g., net8.0, net9.0, net10.0)
Program.cs or Startup.cs Yes The app's service and middleware configuration
_Host.cshtml location Recommended Usually Pages/_Host.cshtml; may be _Host.razor in some projects

Workflow

Commit strategy: Commit after each logical step so the migration is reviewable and bisectable.

Step 1: Update the project file

Update the .csproj file:

  1. Change the Target Framework Moniker (TFM) to the target version:
    <TargetFramework>net8.0</TargetFramework>
    
  2. Update all Microsoft.AspNetCore.*, Microsoft.EntityFrameworkCore.*, Microsoft.Extensions.*, and System.Net.Http.Json package references to the matching version.

For non-Blazor project file changes (nullable reference types, implicit usings, HTTP/3 support, etc.), see the general ASP.NET Core migration guide.

Step 2: Create Routes.razor from App.razor

The old App.razor contains the <Router> component. This content moves to a new Routes.razor file so that App.razor can become the root HTML document component.

  1. Create a new file Routes.razor in the project root.
  2. Move the entire content of App.razor into Routes.razor.
  3. If the content is wrapped in <CascadingAuthenticationState>, remove that wrapper (it will be replaced by a service in Step 5).
  4. Leave App.razor empty for the next step.

The resulting Routes.razor should look similar to:

<Router AppAssembly="@typeof(Program).Assembly">
    <Found Context="routeData">
        <RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
        <FocusOnNavigate RouteData="@routeData" Selector="h1" />
    </Found>
    <NotFound>
        <LayoutView Layout="@typeof(MainLayout)">
            <p>Sorry, there's nothing at this address.</p>
        </LayoutView>
    </NotFound>
</Router>

If the app uses <AuthorizeRouteView> instead of <RouteView>, keep it โ€” it works the same way in Blazor Web Apps.

Step 3: Convert _Host.cshtml to App.razor

Move the HTML shell from Pages/_Host.cshtml into the now-empty App.razor and transform it from a Razor Page into a Razor component:

  1. Remove Razor Page directives โ€” delete @page "/", @using Microsoft.AspNetCore.Components.Web, @namespace, and @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers.

  2. Add component injection โ€” if using environment-conditional error UI, add:

    @inject IHostEnvironment Env
    
  3. Fix the base tag โ€” replace <base href="~/" /> with <base href="/" />.

  4. Replace HeadOutlet Component Tag Helper โ€” replace:

    <component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
    

    with:

    <HeadOutlet @rendermode="InteractiveServer"
    
Pertanyaan umum

Apakah aplikasi tetap interaktif?

Ya. Aplikasi yang diubah memakai rendering server interaktif untuk mempertahankan perilaku saat ini.

Apakah mencakup aplikasi yang sudah diubah?

Tidak. Jika aplikasi sudah memakai model Blazor Web App, tidak perlu konversi.

Apakah mencakup aplikasi WebAssembly?

Tidak. Aplikasi Blazor WebAssembly punya jalur migrasi yang berbeda.

Detail

Deskripsi asli dari pembuat

Guides conversion of a pre-.NET 8 Blazor Server app into a .NET 8+ Blazor Web App. USE FOR: migrating apps that use AddServerSideBlazor and MapBlazorHub to the AddRazorComponents/MapRazorComponents model, converting _Host.cshtml to an App.razor root component, replacing blazor.server.js with blazor.web.js, migrating CascadingAuthenticationState to a service, adopting new Blazor Web App features like enhanced navigation and streaming rendering. DO NOT USE FOR: apps that are already Blazor Web Apps (already use AddRazorComponents and MapRazorComponents), Blazor WebAssembly or hosted Blazor WebAs

repo: dotnet/skills

Popularitas

Bintang GitHub
5.8k
Peringkat
#14559
Lisensi
MIT
Diperbarui
2/11/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • โ€ฆ

Skill lain dari repositori ini

Skill serupa