ViteKit.MsBuild
0.2.0-alpha.6
dotnet add package ViteKit.MsBuild --version 0.2.0-alpha.6
NuGet\Install-Package ViteKit.MsBuild -Version 0.2.0-alpha.6
<PackageReference Include="ViteKit.MsBuild" Version="0.2.0-alpha.6" />
<PackageVersion Include="ViteKit.MsBuild" Version="0.2.0-alpha.6" />
<PackageReference Include="ViteKit.MsBuild" />
paket add ViteKit.MsBuild --version 0.2.0-alpha.6
#r "nuget: ViteKit.MsBuild, 0.2.0-alpha.6"
#:package ViteKit.MsBuild@0.2.0-alpha.6
#addin nuget:?package=ViteKit.MsBuild&version=0.2.0-alpha.6&prerelease
#tool nuget:?package=ViteKit.MsBuild&version=0.2.0-alpha.6&prerelease
ViteKit.Msbuild
Framework-agnostic MSBuild integration for Vite in ASP.NET Core projects
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
Zero Configuration (Recommended)
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:
- New Task Architecture - Migrated from XML-based tasks to high-performance C# tasks
- Auto-Enable by Default - Package now auto-enables when installed (can be disabled)
- Improved File Detection - Better handling of framework-specific files and config files
Migration Steps:
Update Package Reference:
<PackageReference Include="ViteKit.Msbuild" Version="1.x" /> <PackageReference Include="ViteKit.Msbuild" Version="2.0.0" />Remove Old Configuration (if using):
<PropertyGroup> <ViteTasksLoaded>true</ViteTasksLoaded> โ Remove <ViteAssetsEnabled>true</ViteAssetsEnabled> โ Remove </PropertyGroup>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, orvite.config.mjsexists - 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 configbuild.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.
๐ Links
- ๐ฆ NuGet Package: https://www.nuget.org/packages/ViteKit.Msbuild
- ๐ Issues: https://github.com/DigitalParadox/ViteKit/issues
- ๐ฌ Discussions: https://github.com/DigitalParadox/ViteKit/discussions
- ๐ Pull Requests: https://github.com/DigitalParadox/ViteKit/pulls
Made with โค๏ธ for the ASP.NET Core and Vite communities
| Product | Versions 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. |
-
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.