AspNet.AssetManager
4.1.1
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package AspNet.AssetManager --version 4.1.1
NuGet\Install-Package AspNet.AssetManager -Version 4.1.1
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.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AspNet.AssetManager" Version="4.1.1" />
<PackageReference Include="AspNet.AssetManager" />
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.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: AspNet.AssetManager, 4.1.1"
#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.1.1
#: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.1.1
#tool nuget:?package=AspNet.AssetManager&version=4.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
AspNet.AssetManager
Minimal asset manager for ASP.NET Core that reads your frontend tool's manifest (Vite or key-value) and renders the correct tags/paths in development and production.
- Simple TagHelpers:
<link-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.cshtml→Views_Home_Index
- Example:
- You can override it using
ViewData["Bundle"]. Two forms are supported:- A plain name e.g.,
Home_Index - A view-like path starting with a slash e.g.,
/Views/Home/Index, which will be converted to the bundle name:Views_Home_Index
- A plain name e.g.,
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 usetype="module". - Paths point to the dev server:
PublicDevServer+PublicPath.
- Manifest is fetched from the dev server. If the server is not running, you will see:
- Production:
- Manifest is read from disk:
wwwroot+PublicPath+ManifestFile. - Paths are relative to
PublicPath, served byUseStaticFiles().
- Manifest is read from disk:
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
PublicDevServerif 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:
KeyValueorVite. Default isKeyValuewhich matches the format used bywebpack-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 | 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 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.
-
net8.0
- JetBrains.Annotations (>= 2025.2.2)
- System.IO.Abstractions (>= 22.0.16)
-
net9.0
- JetBrains.Annotations (>= 2025.2.2)
- System.IO.Abstractions (>= 22.0.16)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.