convert-blazor-server-to-webapp
ما الذي تفعله
تحوّل هذه المهارة تطبيق Blazor Server قديماً إلى نموذج Blazor Web App الأحدث في .NET 8 أو أحدث. وهي مناسبة لفرق .NET التي لديها تطبيق Blazor Server قديم وتريد الانتقال إلى نموذج الاستضافة الحالي.
متى تستخدمها
- ✓عندما يعمل تطبيق Blazor Server على .NET 6 أو .NET 7 ويحتاج إلى الانتقال إلى .NET 8 أو أحدث.
- ✓عندما ما زال التطبيق يستخدم إعداد hub وصفحة المضيف القديمة في Blazor Server.
- ✓عندما تريد ميزات Blazor Web App الجديدة مع الإبقاء على عرض الخادم التفاعلي.
رابط المهارة
https://github.com/dotnet/skills/blob/main/plugins/dotnet-aspnetcore/skills/convert-blazor-server-to-webapp/SKILL.mdانسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.
طريقة الاستخدام
أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.
رسالة جاهزة للصق
لـ Claude Code أو Codex أو Cursor: شغّله داخل مجلد مشروعك وستُثبَّت المهارة.
نزّل ملف SKILL.md وضعه في مجلد مهارات وكيلك.
مثال على ما تطلبه من الذكاء الاصطناعي
“حوّل تطبيق Blazor Server على .NET 7 الخاص بي إلى Blazor Web App على .NET 8، وأبقه تفاعلياً.”
5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.
كيف تعمل
يحدّث وكيلك إعداد الاستضافة، ويستبدل صفحة المضيف القديمة بمكون جذري، ويحدّث النصوص والخدمات، ويبقي العرض التفاعلي من جهة الخادم حتى يبقى السلوك كما هو.
المحتوى التقني (ملف SKILL.md الأصلي)
النص الأصلي من المؤلف، مباشرة من 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()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"
الأسئلة الشائعة
هل يبقي التطبيق تفاعلياً؟
نعم. يستخدم التطبيق المحوّل عرض الخادم التفاعلي للحفاظ على سلوكه الحالي.
هل تغطي التطبيقات المحوّلة مسبقاً؟
لا. إذا كان التطبيق يستخدم نموذج Blazor Web App بالفعل، فلا حاجة إلى تحويل.
هل تغطي تطبيقات WebAssembly؟
لا. لتطبيقات Blazor WebAssembly مسار ترحيل مختلف.
التفاصيل
الوصف الأصلي من المؤلف
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
الشعبية
- نجوم GitHub
- 5.8k
- الترتيب
- #14559
- الترخيص
- MIT
- آخر تحديث
- 2/11/2026
التعليقات
- …
المزيد من المهارات من هذا المستودع
create-custom-agent
5.8kيساعد وكيلك على إنشاء ملفات وكلاء مخصصين لـVS Code، لكل منهم أدواته وتعليماته وتسليماته إلى وكلاء آخرين.
create-skill
5.8kيساعد وكيلك على إنشاء مهارة وكيل جديدة باسم صالح ووصف محفّز واضح وملف SKILL.md يتبع المعيار.
csharp-scripts
5.8kيساعد وكيلك على تشغيل برنامج C# صغير كملف واحد بأداة سطر أوامر .NET، دون إنشاء مشروع كامل.
dotnet-pinvoke
5.8kيساعد وكيلك على استدعاء مكتبات C أو C++ الأصلية من .NET بشكل صحيح، مع التوقيعات ومعالجة النصوص والذاكرة والمقابض الآمنة.
مهارات مشابهة
angular-developer
280kيساعد وكيلك على كتابة شيفرة Angular وتقديم نصائح لبنية المشروع، ويفيد في بدء المشاريع الجديدة وإنشاء المكونات وتحسين الأداء وإمكانية الوصول.
frontend-a11y
280kيساعد وكيلك على جعل واجهات الويب متاحة للجميع، فيضمن أن المواقع والتطبيقات تعمل جيدًا مع قارئات الشاشة والتنقل بلوحة المفاتيح.
frontend-patterns
280kيطبّق وكيلك أنماط تطوير الواجهات الحديثة، فيحسّن الأداء ويدير الحالة ويتبع أفضل الممارسات في React وNext.js.