본문으로 건너뛰기
Skillpedia
웹사이트 및 UI (프런트엔드)5.8k · #14559

convert-blazor-server-to-webapp

하는 일

이 스킬은 오래된 Blazor Server 앱을 .NET 8 이상의 새 Blazor Web App 모델로 바꿉니다. 현재 호스팅 모델로 옮기려는 오래된 Blazor Server 앱을 가진 .NET 팀을 위한 스킬입니다.

사용하는 경우

  • ✓Blazor Server 앱이 .NET 6이나 .NET 7에 있고 .NET 8 이상으로 옮겨야 할 때.
  • ✓앱이 여전히 예전 Blazor Server 허브와 호스트 페이지 설정을 쓸 때.
  • ✓대화형 서버 렌더링을 유지하면서 새 Blazor Web App 기능을 쓰고 싶을 때.

스킬 링크

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

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/dotnet/skills/blob/main/plugins/dotnet-aspnetcore/skills/convert-blazor-server-to-webapp/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“제 .NET 7 Blazor Server 앱을 .NET 8의 Blazor Web App으로 바꾸고, 대화형 동작은 유지해 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

에이전트가 호스팅 설정을 업데이트하고, 예전 호스트 페이지를 루트 컴포넌트로 바꾸고, 스크립트와 서비스를 고치며, 동작이 같도록 대화형 서버 렌더링을 유지합니다.

기술 내용 (원본 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() 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"
    
자주 묻는 질문

앱이 계속 대화형인가요?

네. 변환된 앱은 현재 동작을 유지하려고 대화형 서버 렌더링을 사용합니다.

이미 변환된 앱에도 적용되나요?

아니요. 앱이 이미 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
업데이트
2026. 11. 2.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬