ViteKit.MsBuild 0.2.0-alpha.4

This is a prerelease version of ViteKit.MsBuild.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package ViteKit.MsBuild --version 0.2.0-alpha.4
                    
NuGet\Install-Package ViteKit.MsBuild -Version 0.2.0-alpha.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ViteKit.MsBuild" Version="0.2.0-alpha.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ViteKit.MsBuild" Version="0.2.0-alpha.4" />
                    
Directory.Packages.props
<PackageReference Include="ViteKit.MsBuild" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ViteKit.MsBuild --version 0.2.0-alpha.4
                    
#r "nuget: ViteKit.MsBuild, 0.2.0-alpha.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ViteKit.MsBuild@0.2.0-alpha.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ViteKit.MsBuild&version=0.2.0-alpha.4&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=ViteKit.MsBuild&version=0.2.0-alpha.4&prerelease
                    
Install as a Cake Tool

ViteKit.Msbuild

Framework-agnostic MSBuild integration for Vite in ASP.NET Core projects

NuGet Package Build Status Tests

Seamlessly integrate Vite with ASP.NET Core - Build Vue, React, Svelte, or any Vite-supported framework directly from dotnet build.


โœจ Features

  • ๐ŸŽฏ Zero Configuration - Auto-detects your project structure and package manager
  • โšก Incremental Builds - Only rebuilds when source files actually change
  • ๐Ÿ”„ Parallel Build Safe - Prevents npm install conflicts in CI/CD
  • ๐ŸŒ Framework Agnostic - Vue, React, Svelte, Solid, Preact, vanilla JS/TS
  • ๐Ÿ“ฆ Package Manager Smart - Auto-detects npm, pnpm, yarn, or bun
  • ๐Ÿ›ก๏ธ Enterprise Ready - Robust error handling and comprehensive logging
  • ๐ŸŽ›๏ธ MSBuild Native - Uses proper MSBuild targets, not hacky scripts

๐Ÿš€ Quick Start

1. Install the NuGet Package

dotnet add package ViteKit.Msbuild

2. Initialize Your Frontend

Choose your preferred framework:

# Vue + TypeScript
npm create vite@latest . -- --template vue-ts

# React + TypeScript  
npm create vite@latest . -- --template react-ts

# Svelte + TypeScript
npm create vite@latest . -- --template svelte-ts

# Or any other Vite template

3. Build

dotnet build

That's it! Your Vite assets are now built automatically during MSBuild.


๐Ÿ“‹ Requirements

  • .NET 6.0+ (supports .NET 8, .NET 9)
  • Node.js 18+
  • Vite 4.0+ or Vite 5.0+
  • ASP.NET Core project (Web, MVC, API, Blazor)

โš™๏ธ Configuration

ViteKit.Msbuild works out-of-the-box with sensible defaults:

<PackageReference Include="ViteKit.Msbuild" Version="2.0.0" />

Custom Configuration (Optional)

Override defaults when needed:

<PropertyGroup>
  
  <EnableViteBuild>false</EnableViteBuild>
  
  
  <ViteConfigFile>custom.vite.config.ts</ViteConfigFile>
  
  
  <ViteOutputDir>wwwroot/dist</ViteOutputDir>
  
  
  <PackageManager>pnpm</PackageManager>
  
  
  <ViteMode>staging</ViteMode>
  
  
  <ViteBuildTiming>AfterCSharp</ViteBuildTiming>
</PropertyGroup>

Advanced File Filtering

<ItemGroup>
  
  <ViteInputFiles Include="custom/**/*.ts" />
  <ViteInputFiles Include="shared/**/*.vue" />
  
  
  <ViteInputFiles Remove="legacy/**/*" />
  <ViteInputFiles Remove="temp/**/*" />
</ItemGroup>

๐Ÿ“ฆ Package Manager Support

Automatically detects and works with all major package managers:

Package Manager Lock File Install Command Notes
npm package-lock.json npm ci Default Node.js package manager
pnpm pnpm-lock.yaml pnpm install --frozen-lockfile Fast, disk-space efficient
Yarn yarn.lock yarn install --frozen-lockfile Classic and Berry (PnP) supported
Bun bun.lockb bun install --frozen-lockfile Ultra-fast JavaScript runtime

Package Manager Conflicts

If multiple lock files are detected, ViteKit.Msbuild provides clear guidance:

โš ๏ธ  Multiple package manager lock files detected: yarn.lock, package-lock.json
๐Ÿ’ก To resolve with yarn:
   rm package-lock.json && yarn install --frozen-lockfile
๐Ÿ’ก Then commit the updated yarn lock file to your repository

๐Ÿ—๏ธ Build Integration

MSBuild Target Execution Order

ResolveStaticWebAssetsInputs
โ”œโ”€โ”€ ShowViteDiagnostics (if verbosity >= detailed)
โ”œโ”€โ”€ ResolveViteMode (Configuration โ†’ Vite mode mapping)
โ”œโ”€โ”€ ValidateViteSetup (validation + welcome message)
โ”œโ”€โ”€ EnsureNodeDependencies (npm install if needed)
โ””โ”€โ”€ ViteBuildAssets (main Vite build)

Build Timing Options

Control when Vite builds relative to C# compilation:

<PropertyGroup>
  
  <ViteBuildTiming>BeforeCSharp</ViteBuildTiming>
  
  
  <ViteBuildTiming>AfterCSharp</ViteBuildTiming>
</PropertyGroup>

Verbosity Mapping

MSBuild verbosity automatically maps to Vite log levels:

dotnet build -v:quiet     # โ†’ vite build --logLevel silent
dotnet build -v:minimal   # โ†’ vite build --logLevel warn
dotnet build -v:normal    # โ†’ vite build --logLevel info
dotnet build -v:detailed  # โ†’ vite build --logLevel info + diagnostics
dotnet build -v:diag      # โ†’ vite build --logLevel debug

๐Ÿข Enterprise & Monorepo Support

Multi-SPA Configuration

For complex applications with multiple frontend entry points:

<ItemGroup>
  <ViteConfig Include="Areas/Admin/vite.config.ts">
    <BuildId>admin</BuildId>
    <OutputDir>wwwroot/admin</OutputDir>
    <Mode>development</Mode>
  </ViteConfig>
  
  <ViteConfig Include="Areas/Portal/vite.config.ts">
    <BuildId>portal</BuildId>
    <OutputDir>wwwroot/portal</OutputDir>
    <Mode>production</Mode>
  </ViteConfig>
</ItemGroup>

See the Multi-SPA Guide for complete documentation.

Monorepo Project Structure

Option 1: Shared Package.json

MyProject/
โ”œโ”€โ”€ package.json              โ† Shared dependencies
โ”œโ”€โ”€ vite.config.ts            โ† Shared Vite config  
โ””โ”€โ”€ src/
    โ””โ”€โ”€ WebApp/
        โ””โ”€โ”€ WebApp.csproj     โ† References ViteKit.Msbuild

Option 2: Project-Specific Dependencies

MyProject/
โ””โ”€โ”€ src/
    โ””โ”€โ”€ WebApp/
        โ”œโ”€โ”€ package.json      โ† WebApp-specific dependencies
        โ”œโ”€โ”€ vite.config.ts    โ† WebApp-specific config
        โ””โ”€โ”€ WebApp.csproj     โ† References ViteKit.Msbuild

๐Ÿงช Framework Examples

Vue 3 + TypeScript

npm create vite@latest . -- --template vue-ts

vite.config.ts:

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
  plugins: [vue()],
  build: {
    outDir: 'wwwroot',
    manifest: true,
    rollupOptions: {
      input: 'src/main.ts'
    }
  }
})

React + TypeScript

npm create vite@latest . -- --template react-ts

vite.config.ts:

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

export default defineConfig({
  plugins: [react()],
  build: {
    outDir: 'wwwroot',
    manifest: true,
    rollupOptions: {
      input: 'src/main.tsx'
    }
  }
})

Svelte + TypeScript

npm create vite@latest . -- --template svelte-ts

vite.config.ts:

import { defineConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'

export default defineConfig({
  plugins: [svelte()],
  build: {
    outDir: 'wwwroot',
    manifest: true,
    rollupOptions: {
      input: 'src/main.ts'
    }
  }
})

๐Ÿ”„ Migration Guide

From ViteKit.Msbuild 1.x to 2.x

Breaking Changes:

  1. New Task Architecture - Migrated from XML-based tasks to high-performance C# tasks
  2. Auto-Enable by Default - Package now auto-enables when installed (can be disabled)
  3. Improved File Detection - Better handling of framework-specific files and config files

Migration Steps:

  1. Update Package Reference:

    
    <PackageReference Include="ViteKit.Msbuild" Version="1.x" />
    
    
    <PackageReference Include="ViteKit.Msbuild" Version="2.0.0" />
    
  2. Remove Old Configuration (if using):

    
    <PropertyGroup>
      <ViteTasksLoaded>true</ViteTasksLoaded>  โ† Remove
      <ViteAssetsEnabled>true</ViteAssetsEnabled>  โ† Remove
    </PropertyGroup>
    
  3. Verify Output Directory:

    
    <PropertyGroup>
      <ViteOutputDir>wwwroot</ViteOutputDir>
    </PropertyGroup>
    

New Features in 2.x:

  • โœ… Automatic package manager detection
  • โœ… Better error messages and validation
  • โœ… Improved incremental build performance
  • โœ… Enhanced monorepo support
  • โœ… Comprehensive logging and diagnostics

๐Ÿ› ๏ธ Troubleshooting

Common Issues

Build fails with "Task attempted to log before it was initialized"

  • Fixed in 2.x - This was resolved with the new C# task architecture

Multiple package manager lock files detected

  • Choose one package manager and remove other lock files
  • Follow the guidance messages for your preferred package manager

Vite config not found

  • Ensure vite.config.ts, vite.config.js, or vite.config.mjs exists
  • Use <ViteConfigFile> to specify custom location

Assets not appearing in output

  • Check that Vite build outputs to the correct directory (usually wwwroot)
  • Verify <ViteOutputDir> property matches your Vite config build.outDir

Debug Information

Enable detailed logging to diagnose issues:

dotnet build -v:detailed

This shows:

  • โœ… Package manager detection
  • โœ… File discovery process
  • โœ… Vite command execution
  • โœ… Build timing information

๐Ÿ“ˆ Performance

Incremental Build Optimization

ViteKit.Msbuild uses MSBuild's incremental build system:

  • Input Files: All frontend source files + config files
  • Output Marker: Timestamp file in obj/ directory
  • Build Logic: Only rebuilds if inputs are newer than outputs

Typical Performance:

  • Clean Build: 5-15 seconds (depending on project size)
  • Incremental Build: 0.1-0.5 seconds (if no changes)
  • Changed File Build: 1-5 seconds (Vite HMR speed)

CI/CD Optimization

For optimal CI/CD performance:

# GitHub Actions example
- name: Build
  run: dotnet build --configuration Release --verbosity minimal
  
# Only install dependencies if lock file changed
- name: Cache Node modules
  uses: actions/cache@v3
  with:
    path: node_modules
    key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}

๐Ÿค Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

# Clone the repository
git clone https://github.com/DigitalParadox/ViteKit.Msbuild.git
cd ViteKit.Msbuild

# Restore dependencies
dotnet restore

# Run tests
dotnet test

# Build package
.\build-package.ps1 -Version "1.0.0"

Test Coverage

Current test coverage: 427 tests passing (100% pass rate)

  • โœ… Core Tasks: OrchestrateBuildTask, CollectViteInputFilesTask, ViteConfigurationResolver
  • โœ… Resolver Tasks: ViteConfigurationResolver, ViteConfigDependencyResolver, ViteModeResolver
  • โœ… Command Builders: ViteCommandFactory, ScriptBasedCommandBuilder, DirectToolCommandBuilder, CustomCommandBuilder
  • โœ… Validation: ViteConfig, ValidateViteConfig
  • โœ… Orchestration: OrchestrateBuildTask (multi-config builds, dependency ordering, incremental builds)
  • โœ… Build Integration: MSBuild target execution, parallel builds, marker files
  • โœ… Framework Support: Vue, React, Svelte file detection
  • โœ… Package Managers: npm, pnpm, yarn, bun detection and command generation
  • โœ… Advanced Features: Dependency graphs, topological sorting, circular detection, mode resolution, architecture detection
  • โœ… Error Scenarios: Validation, conflict resolution, helpful messages, encoding compatibility

๐Ÿ“„ License

This project is licensed under the MIT License.



Made with โค๏ธ for the ASP.NET Core and Vite communities

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.0-alpha.6 162 11/24/2025
0.2.0-alpha.5 148 11/24/2025
0.2.0-alpha.4 157 11/24/2025
0.2.0-alpha.3 162 11/24/2025

See GitHub Releases for autogenerated notes.