Swallow.Blazor.StaticAssetPaths
1.0.0
dotnet add package Swallow.Blazor.StaticAssetPaths --version 1.0.0
NuGet\Install-Package Swallow.Blazor.StaticAssetPaths -Version 1.0.0
<PackageReference Include="Swallow.Blazor.StaticAssetPaths" Version="1.0.0" />
<PackageVersion Include="Swallow.Blazor.StaticAssetPaths" Version="1.0.0" />
<PackageReference Include="Swallow.Blazor.StaticAssetPaths" />
paket add Swallow.Blazor.StaticAssetPaths --version 1.0.0
#r "nuget: Swallow.Blazor.StaticAssetPaths, 1.0.0"
#:package Swallow.Blazor.StaticAssetPaths@1.0.0
#addin nuget:?package=Swallow.Blazor.StaticAssetPaths&version=1.0.0
#tool nuget:?package=Swallow.Blazor.StaticAssetPaths&version=1.0.0
Compile-time correct paths to static web assets
There's a mistake in this Blazor component. Can you spot it?
<!DOCTYPE html>
<html lang="en">
<head>
<title>My cool page</title>
<link rel="stylesheet" href="@Assets["global.css"]" />
<link rel="stylesheet" href="@Assets["tehme.css"]" />
</head>
<body>
</body>
</html>
That's right, it's tehme.css
instead of theme.css
! Easy to stop, especially
when you've got many of these links across many components. But here's the
thing: These assets are known at compile time. Why is there no way to
have the compiler assist you when writing your code?
Swallow.Blazor.StaticAssetPaths
is a source generator to give you just that:
<!DOCTYPE html>
<html lang="en">
<head>
<title>My cool page</title>
<link rel="stylesheet" href="@Assets[AssetPaths.Wwwroot.GlobalCss]" />
<link rel="stylesheet" href="@Assets[AssetPaths.Wwwroot.ThemeCss]" />
</head>
<body>
</body>
</html>
Ah, way better. Compile-time constants. What does the generated file look like?
namespace YourProject;
public static class AssetPaths
{
public static class Wwwroot
{
/// <summary>
/// Points to <c>wwwroot/global.css</c>
/// </summary>
public static readonly string GlobalCss = "global.css";
/// <summary>
/// Points to <c>wwwroot/theme.css</c>
/// </summary>
public static readonly string ThemeCss = "theme.css";
}
}
You even get a small comment showing you the exact file path!
Usage
Simply reference the package and you're good to go:
<PackageReference Include="Swallow.Blazor.StaticAssetPaths" />
By default, the generator will collect the following files:
wwwroot/**/*
**/*.razor.js
**/*.cshtml.js
If you want to include some files, simply add these items to AdditionalFiles
:
<AdditionalFiles Include="Resources/translations.js" SourceItemGroup="Content" />
If you want to exclude items, you can... well... exclude them... or you can
override the standard properties DefaultItemExcludes
and
DefaultExcludesInProjectFolder
.
Learn more about Target Frameworks and .NET Standard.
This package has 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 |
---|---|---|
1.0.0 | 135 | 6/30/2025 |