Quick Start
This walkthrough takes you from an ASP.NET Core Razor Pages project with a Vite SPA folder to a running integration — first in development with hot module replacement, then a production build.
We’ll use a React app in a folder called ReactApp, but the steps are the same for Svelte, Vue,
or Solid.
The target layout
Section titled “The target layout”DirectoryYourApp/
- Program.cs
- appsettings.Development.json
DirectoryPages/
- Index.cshtml the page that hosts the SPA
- _ViewImports.cshtml
DirectoryReactApp/ your Vite SPA
- vite.config.ts
- package.json
Directorysrc/
- main.tsx the entrypoint
Directorywwwroot/ Vite build output lands here
- …
Step 1 — Install and register
Section titled “Step 1 — Install and register”If you have not already, follow Installation to add the
TechGems.ViteDotNet NuGet package and the vite-dotnet Vite plugin. In short:
builder.Services.AddViteIntegration(builder.Configuration);@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers@addTagHelper *, ViteDotNetimport { defineConfig } from 'vite'import react from '@vitejs/plugin-react'import ViteDotNetPlugin from 'vite-dotnet'
export default defineConfig({ plugins: [ react(), ViteDotNetPlugin('src/main.tsx', 'root'), ],})Step 2 — Tell the back end the app folder name
Section titled “Step 2 — Tell the back end the app folder name”{ "ViteDotNet": "ReactApp"}Step 3 — Render the SPA in a page
Section titled “Step 3 — Render the SPA in a page”Add the development tag helper to the Razor page that should host the SPA:
@page@model YourApp.Pages.IndexModel@{ Layout = null;}
<dev-vite-scripts app-name="ReactApp" />Step 4 — Run both in development
Section titled “Step 4 — Run both in development”-
Start the Vite dev server from the SPA folder:
Terminal window cd ReactAppnpm run devOn start, the plugin writes
wwwroot/ReactApp/manifest.dev.jsondescribing the running server (its port, your entrypoint, the container id, and whether it’s React). -
Run the ASP.NET Core app in another terminal:
Terminal window dotnet run -
Open the page. The
<dev-vite-scripts>helper readsmanifest.dev.jsonand injects the Vite client and your entrypoint from the dev server, so you get full hot module replacement inside your Razor page.
Step 5 — Build for production
Section titled “Step 5 — Build for production”-
Build the SPA:
Terminal window cd ReactAppnpm run buildVite writes the hashed bundle into
wwwroot/ReactApp/along with its ownmanifest.jsonand the plugin’smanifest.prod.json. -
Swap to the production tag helper on the page:
Pages/Index.cshtml <prod-vite-scripts app-name="ReactApp" />In production,
<prod-vite-scripts>reads the hashed asset paths from Vite’smanifest.jsonand the container id frommanifest.prod.json, and renders the final<script>and<link>tags — no dev server involved.
You now have a Vite SPA fully integrated into your ASP.NET Core app. To understand what’s happening under the hood, read How It Works.