AspNet.AssetManager 4.2.0

dotnet add package AspNet.AssetManager --version 4.2.0
                    
NuGet\Install-Package AspNet.AssetManager -Version 4.2.0
                    
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="AspNet.AssetManager" Version="4.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AspNet.AssetManager" Version="4.2.0" />
                    
Directory.Packages.props
<PackageReference Include="AspNet.AssetManager" />
                    
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 AspNet.AssetManager --version 4.2.0
                    
#r "nuget: AspNet.AssetManager, 4.2.0"
                    
#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 AspNet.AssetManager@4.2.0
                    
#: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=AspNet.AssetManager&version=4.2.0
                    
Install as a Cake Addin
#tool nuget:?package=AspNet.AssetManager&version=4.2.0
                    
Install as a Cake Tool

AspNet.AssetManager

Build status codecov NuGet Version

Asset manager for ASP.NET Core that enables use of modern frontend tooling.

  • Simple TagHelpers: <link-bundle />, <style-bundle /> and <script-bundle />
  • Automatic bundle name inference from the active view.
  • Optional per-view overrides via ViewData["Bundle"]
  • Works with a dev server (e.g., Vite, Webpack) in development, and static files in production.

See the template repository, for usage examples: AspNet.Frontends

Install

dotnet add package AspNet.AssetManager

Quick start

Register services in Program.cs:

using AspNet.AssetManager;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddAssetManager(builder.Configuration, builder.Environment);

Register tag helpers in Views/_ViewImports.cshtml:

@addTagHelper *, AspNet.AssetManager

Use in Views/Shared/_Layout.cshtml:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>@ViewData["Title"] - AspNet.AssetManager</title>
  <link-bundle fallback="Layout" />
</head>
<body>
  @RenderBody()
  <script-bundle defer fallback="Layout" />
  @await RenderSectionAsync("Scripts", required: false)
</body>
</html>

How bundle names are chosen

  • By default, the bundle name is inferred from the active view.
    • Example: /Views/Home/Index.cshtmlViews_Home_Index
  • You can override the bundle chosen from view inference using ViewData["Bundle"].
  • A bundle name can be directly provided to a tag helper using the name attribute.

Development vs. production behavior

  • Development:
    • Manifest is fetched from the dev server. If the server is not running, you will see: Development server not started!.
    • Tag helpers add crossorigin="anonymous" automatically; with "ManifestType": "Vite", script tags also use type="module".
    • Paths point to the dev server: PublicDevServer + PublicPath.
  • Production:
    • Manifest is read from disk: wwwroot + PublicPath + ManifestFile.
    • Paths are relative to PublicPath, served by UseStaticFiles().

Configuration (appsettings.json)

{
  "AssetManager": {
    "PublicDevServer": "http://localhost:5173",
    "InternalDevServer": "http://localhost:5173",
    "PublicPath": "/dist/",
    "ManifestFile": "assets-manifest.json",
    "ManifestType": "KeyValue"
  }
}
  • PublicDevServer: required. The browser-facing URL of your dev server (e.g., Vite).
  • InternalDevServer: optional. If your app runs behind Docker/WSL/etc., point this to where the server is reachable from the app process. Falls back to PublicDevServer if omitted.
  • PublicPath: the public base path for built assets. In production this is under wwwroot; in development it is appended to the dev server URL. Default is /dist/.
  • ManifestFile: the filename of your manifest. Default is assets-manifest.json.
  • ManifestType: KeyValue or Vite. Default is KeyValue which matches the format used by webpack-assets-manifest.

Manual rendering

If you prefer code-based rendering or need more control, inject IAssetService.

@using AspNet.AssetManager
  
@inject IAssetService AssetService

@{
    var bundle = ViewData.GetBundleName() ?? Html.GetBundleName();
}

/* Base paths */
@AssetService.WebPath

/* Resolve paths */
@await AssetService.GetBundlePathAsync("SomeBundle.js")
@await AssetService.GetBundlePathAsync("SomeBundle", FileType.JS)

/* Script tags */
@await AssetService.GetScriptTagAsync("SomeBundle")
@await AssetService.GetScriptTagAsync("SomeBundle", ScriptLoad.Async)
@await AssetService.GetScriptTagAsync("SomeBundle", "FallbackBundle", ScriptLoad.Async)

/* Link tags */
@await AssetService.GetLinkTagAsync("SomeBundle")

/* Style tags */
@await AssetService.GetStyleTagAsync("SomeBundle")
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 is compatible.  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.

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
4.2.0 257 10/15/2025
4.1.1 187 10/14/2025
4.1.0 177 10/14/2025
4.0.1 213 8/17/2025
4.0.0 184 8/14/2025
3.0.0 181 7/31/2025