Skip to content

Installation

Vite.NET has two halves: a NuGet package for your ASP.NET Core app, and a Vite plugin for your SPA. This page installs both. If you are starting from scratch, the Quick Start walks through the whole project layout.

  1. Add the package to your ASP.NET Core project

    The current release is 1.0.0. Because it is a prerelease, pass the version explicitly (or --prerelease) so NuGet does not skip it:

    dotnet add package TechGems.ViteDotNet --version 1.0.0

    Or, editing the .csproj directly:

    <PackageReference Include="TechGems.ViteDotNet" Version="1.0.0" />
  2. Register the integration in Program.cs

    using ViteDotNet;
    var builder = WebApplication.CreateBuilder(args);
    builder.Services.AddRazorPages();
    builder.Services.AddViteIntegration(builder.Configuration);
  3. Register the tag helpers in _ViewImports.cshtml

    @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
    @addTagHelper *, ViteDotNet
  1. Add the plugin to your SPA folder

    From inside your SPA directory (e.g. ReactApp/). The plugin has its own release track, so install 1.0.0 here — as a prerelease it is not picked up by a plain npm install vite-dotnet:

    npm install vite-dotnet@1.0.0
  2. Register it in vite.config.ts

    Add the plugin after your framework plugin, passing your entrypoint and the id of the element the SPA mounts into:

    import { defineConfig } from 'vite'
    import react from '@vitejs/plugin-react'
    import ViteDotNetPlugin from 'vite-dotnet'
    export default defineConfig({
    plugins: [
    react(),
    ViteDotNetPlugin('src/main.tsx', 'root'),
    ],
    })

Add the SPA’s directory name to your configuration under the ViteDotNet section. This is the only backend configuration required.

appsettings.Development.json
{
"ViteDotNet": "ReactApp"
}

That’s it — everything else (entrypoint, container element id, dev-server port, whether the app is React) is generated by the plugin at dev-server start and build time. Continue to the Quick Start to render your SPA into a page.