AspNet.AssetManager
4.0.1
dotnet add package AspNet.AssetManager --version 4.0.1
NuGet\Install-Package AspNet.AssetManager -Version 4.0.1
<PackageReference Include="AspNet.AssetManager" Version="4.0.1" />
<PackageVersion Include="AspNet.AssetManager" Version="4.0.1" />
<PackageReference Include="AspNet.AssetManager" />
paket add AspNet.AssetManager --version 4.0.1
#r "nuget: AspNet.AssetManager, 4.0.1"
#:package AspNet.AssetManager@4.0.1
#addin nuget:?package=AspNet.AssetManager&version=4.0.1
#tool nuget:?package=AspNet.AssetManager&version=4.0.1
AspNet.AssetManager
See the template repository, for usage examples: AspNet.Frontends
Initialize AspNet.AssetManager
in Program.cs
:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddAssetManager(builder.Configuration, builder.Environment);
Use extensions to get the bundle name:
var bundle = ViewData.GetBundleName() // Gets the bundle name from ViewData["Bundle"]
var bundle = Html.GetBundleName() // Generates the bundle name from the view context
Recommended use in eg. _Layout.cshtml
:
var bundle = ViewData.GetBundleName() ?? Html.GetBundleName();
// Generates the bundle name from the view context if not overridin in ViewData["Bundle"]
Use AssetService
to get assets:
@inject IAssetService AssetService
@await AssetService.WebPath
// Returns: /web/path
@await AssetService.GetBundlePathAsync("SomeBundle.js")
// Returns: /web/path/SomeBundle.js
@await AssetService.GetScriptTagAsync("SomeBundle")
// Generates: <script src="/web/path/SomeBundle.js"></script>
@await AssetService.GetLinkTagAsync("SomeBundle")
// Generates: <link href="/web/path/SomeBundle.css" rel="stylesheet" />
@await AssetService.GetStyleTagAsync("SomeBundle")
// Generates: <style>Inlined CSS</style
Overloads exist on GetBundlePathAsync
in case no extension is applied for the bundle name:
@await AssetService.GetBundlePathAsync("SomeBundle", FileType.JS)
// Returns: /web/path/SomeBundle.js
Overloads exist on GetScriptTagAsync
to change the load behavior to e.g. async
and/or defer
:
@await AssetService.GetScriptTagAsync("SomeBundle", ScriptLoad.Async)
// Generates: <script src="/web/path/SomeBundle.js" async></script>
A fallback bundle can be specified on: GetScriptTagAsync
, GetLinkTagAsync
, GetStyleTagAsync
:
@await AssetService.GetScriptTagAsync("SomeBundle", fallback: "FallbackBundle")
// Generates: <script src="/web/path/SomeBundle.js"></script>
// Or if 'SomeBundle' does not exist: <script src="/web/path/FallbackBundle.js"></script>
Configuration: appsettings.json
{
"AssetManager": {
"PublicDevServer": "http://localhost:5173",
"InternalDevServer": "http://localhost:5173",
"PublicPath": "/dist/",
"ManifestFile": "assets-manifest.json",
"ManifestType": "KeyValue"
}
}
PublicDevServer
is the only required setting.ManifestType
can be eitherKeyValue
orVite
.
Example: _Layout.cshtml
@using AspNet.AssetManager
@inject IAssetService AssetService
@{
var bundle = ViewData.GetBundleName() ?? Html.GetBundleName();
}
<!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>
@await AssetService.GetLinkTagAsync(bundle, fallback: "Layout");
</head>
<body>
@RenderBody()
@await AssetService.GetScriptTagAsync(bundle, fallback: "Layout", ScriptLoad.Defer);
@await RenderSectionAsync("Scripts", required: false)
</body>
</html>
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. |
-
net8.0
- System.IO.Abstractions (>= 22.0.15)
-
net9.0
- System.IO.Abstractions (>= 22.0.15)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.