convert-blazor-server-to-webapp
Skill này làm gì
Skill này chuyển một ứng dụng Blazor Server cũ sang mô hình Blazor Web App mới hơn trong .NET 8 trở lên. Skill dành cho các đội .NET có ứng dụng Blazor Server cũ muốn chuyển sang mô hình lưu trữ hiện tại.
Khi nào nên dùng
- ✓Khi ứng dụng Blazor Server của bạn dùng .NET 6 hoặc .NET 7 và cần chuyển sang .NET 8 trở lên.
- ✓Khi ứng dụng vẫn dùng thiết lập hub và trang host Blazor Server cũ.
- ✓Khi bạn muốn các tính năng Blazor Web App mới mà vẫn giữ render tương tác phía server.
Liên kết skill
https://github.com/dotnet/skills/blob/main/plugins/dotnet-aspnetcore/skills/convert-blazor-server-to-webapp/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Chuyển ứng dụng Blazor Server .NET 7 của tôi sang Blazor Web App trên .NET 8 và giữ nó tương tác.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent cập nhật thiết lập lưu trữ, thay trang host cũ bằng một component gốc, cập nhật script và service, và giữ render tương tác phía server để hành vi không đổi.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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()andMapBlazorHub()inProgram.cs(orStartup.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
AddRazorComponentsandMapRazorComponents. 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:
- Change the Target Framework Moniker (TFM) to the target version:
<TargetFramework>net8.0</TargetFramework> - Update all
Microsoft.AspNetCore.*,Microsoft.EntityFrameworkCore.*,Microsoft.Extensions.*, andSystem.Net.Http.Jsonpackage 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.
- Create a new file
Routes.razorin the project root. - Move the entire content of
App.razorintoRoutes.razor. - If the content is wrapped in
<CascadingAuthenticationState>, remove that wrapper (it will be replaced by a service in Step 5). - Leave
App.razorempty 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:
Remove Razor Page directives — delete
@page "/",@using Microsoft.AspNetCore.Components.Web,@namespace, and@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers.Add component injection — if using environment-conditional error UI, add:
@inject IHostEnvironment EnvFix the base tag — replace
<base href="~/" />with<base href="/" />.Replace HeadOutlet Component Tag Helper — replace:
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />with:
<HeadOutlet @rendermode="InteractiveServer"
Câu hỏi thường gặp
Skill có giữ ứng dụng tương tác không?
Có. Ứng dụng sau chuyển đổi dùng render tương tác phía server để giữ hành vi hiện tại.
Skill có áp dụng cho ứng dụng đã chuyển đổi không?
Không. Nếu ứng dụng đã dùng mô hình Blazor Web App, không cần chuyển đổi.
Skill có bao quát ứng dụng WebAssembly không?
Không. Ứng dụng Blazor WebAssembly có một lộ trình chuyển đổi khác.
Chi tiết
Mô tả gốc của tác giả
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
Độ phổ biến
- Sao GitHub
- 5.8k
- Vị trí xếp hạng
- #14559
- Giấy phép
- MIT
- Cập nhật
- 2/11/2026
Bình luận
- …
Thêm skill từ kho mã này
create-custom-agent
5.8kGiúp agent của bạn tạo file custom agent cho VS Code, với các tool, hướng dẫn và handoff riêng sang agent khác.
create-skill
5.8kGiúp agent của bạn tạo một agent skill mới với tên hợp lệ, mô tả kích hoạt rõ ràng và file SKILL.md đúng tiêu chuẩn.
csharp-scripts
5.8kGiúp agent của bạn chạy một chương trình C# nhỏ dưới dạng một file duy nhất bằng công cụ dòng lệnh .NET, không cần tạo project đầy đủ.
dotnet-pinvoke
5.8kGiúp agent của bạn gọi các thư viện native C hoặc C++ từ .NET đúng cách, gồm khai báo chữ ký, xử lý chuỗi, bộ nhớ và safe handle.
Skill tương tự
angular-developer
280kGiúp agent của bạn viết code Angular và tư vấn cấu trúc dự án, hữu ích khi bắt đầu dự án mới hoặc cải thiện hiệu suất.
frontend-a11y
280kGiúp agent của bạn làm cho giao diện web dễ tiếp cận với mọi người. Đảm bảo website và ứng dụng hoạt động tốt với trình đọc màn hình và điều hướng bằng bàn phím.
frontend-patterns
280kGiúp agent của bạn áp dụng các mẫu hiện đại trong phát triển frontend. Tối ưu hiệu năng, quản lý trạng thái và tuân theo thực hành tốt nhất với React và Next.js.