MagicConstants 1.0.0-preview-05
dotnet add package MagicConstants --version 1.0.0-preview-05
NuGet\Install-Package MagicConstants -Version 1.0.0-preview-05
<PackageReference Include="MagicConstants" Version="1.0.0-preview-05" />
<PackageVersion Include="MagicConstants" Version="1.0.0-preview-05" />
<PackageReference Include="MagicConstants" />
paket add MagicConstants --version 1.0.0-preview-05
#r "nuget: MagicConstants, 1.0.0-preview-05"
#addin nuget:?package=MagicConstants&version=1.0.0-preview-05&prerelease
#tool nuget:?package=MagicConstants&version=1.0.0-preview-05&prerelease
Magic Constants
Magic Constants is a dotnet source generator that generates C# constants from files in your project. It can also minify files and set cache control headers for routes.
This is especially useful for web projects where you want to reference files in your code without hardcoding the paths nor having to manage the string constants.
Global settings in your project:
<PropertyGroup>
<MagicConstantsVisibility>public</MagicConstantsVisibility>
<MagicConstantsRoutes>true</MagicConstantsRoutes>
<MagicConstantsRoutesCacheControl>public, max-age=604800</MagicConstantsRoutesCacheControl>
<MagicConstantsMinify>true</MagicConstantsMinify>
</PropertyGroup>
Specific settings ( Note: if not specified, global settings will be used instead )
<ItemGroup>
<AdditionalFiles Include="**\*.html" MagicClass="Pages" MagicRemoveRouteExtension="true" MagicCacheControl="public, max-age=86400" MagicMinify="true" />
<AdditionalFiles Include="**\*.css" MagicClass="Assets" MagicMinify="true" />
<AdditionalFiles Include="**\*.js" MagicClass="Assets" MagicMinify="true" />
<AdditionalFiles Include="**\*.svg" MagicClass="Images" />
<AdditionalFiles Include="**\*.png" MagicClass="Images" />
<AdditionalFiles Include="**\*.ico" MagicClass="Images" />
</ItemGroup>
When MagicConstantsRoutes
is enabled, it will generate an aspnet route for every file. All you have to do, is call the mapping method:
app.MapViews();
Magic Constants also allows you to replace variables inside your .htm, .html, .css and .js files. You can use the following syntax:
<a href="index.html?noCache={MAGIC_TIME}">
<a href="index.html?noCache={MAGIC_HASH}">
MAGIC_TIME will use the Unix Timestamp in seconds during build, while MAGIC_HASH will try and make a unique but consistent hash out of the timestamp, which will end up as:
<a href="index.html?noCache=1746028631">
<a href="index.html?noCache=LHf1JfsN">
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.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 |
---|---|---|
1.0.0-preview-05 | 14 | 4/30/2025 |
1.0.0-preview-04 | 23 | 4/30/2025 |
1.0.0-preview-03 | 52 | 3/15/2025 |
1.0.0-preview-02 | 71 | 12/11/2024 |
1.0.0-preview-01 | 63 | 12/11/2024 |