Meziantou.Framework.EmbeddedConstantsGenerator 1.0.2

Prefix Reserved
dotnet add package Meziantou.Framework.EmbeddedConstantsGenerator --version 1.0.2
                    
NuGet\Install-Package Meziantou.Framework.EmbeddedConstantsGenerator -Version 1.0.2
                    
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="Meziantou.Framework.EmbeddedConstantsGenerator" Version="1.0.2">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Meziantou.Framework.EmbeddedConstantsGenerator" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Meziantou.Framework.EmbeddedConstantsGenerator">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
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 Meziantou.Framework.EmbeddedConstantsGenerator --version 1.0.2
                    
#r "nuget: Meziantou.Framework.EmbeddedConstantsGenerator, 1.0.2"
                    
#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 Meziantou.Framework.EmbeddedConstantsGenerator@1.0.2
                    
#: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=Meziantou.Framework.EmbeddedConstantsGenerator&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Meziantou.Framework.EmbeddedConstantsGenerator&version=1.0.2
                    
Install as a Cake Tool

Meziantou.Framework.EmbeddedConstantsGenerator

Generate a static partial class that exposes selected files as text and byte constants.

Installation

dotnet package add Meziantou.Framework.EmbeddedConstantsGenerator

Usage

<PropertyGroup>
  <EmbeddedConstantsNamespace>MyApp.Generated</EmbeddedConstantsNamespace>
  <EmbeddedConstantsClassName>EmbeddedFiles</EmbeddedConstantsClassName>
</PropertyGroup>

<ItemGroup>
  <EmbeddedConstant Include="Assets\hello.txt" Kind="Text" />
  <EmbeddedConstant Include="Assets\logo.bin" Kind="Binary" />
  <EmbeddedConstant Include="Assets\config.json"
                    Kind="Both"
                    Name="ConfigJson" />
</ItemGroup>

The package uses an MSBuild task so binary files are read byte-for-byte during the build. The generated type is always static partial. Text files generate a const string member. Binary files generate a ReadOnlySpan<byte> member. Files marked as Both generate both members.

namespace MyApp.Generated;

internal static partial class EmbeddedFiles
{
    public const string HelloText = "...";
    public static ReadOnlySpan<byte> LogoBytes => new byte[] { ... };
    public const string ConfigJsonText = "...";
    public static ReadOnlySpan<byte> ConfigJsonBytes => new byte[] { ... };
}

MSBuild Properties

Property Default Description
EmbeddedConstantsNamespace $(RootNamespace), then $(MSBuildProjectName) Namespace of the generated class
EmbeddedConstantsClassName EmbeddedConstants Name of the generated class
EmbeddedConstantsClassVisibility internal Generated class visibility: internal or public
EmbeddedConstantsMemberVisibility public Generated member visibility: internal or public
EmbeddedConstantsOutputPath $(IntermediateOutputPath)\Meziantou.Framework.EmbeddedConstantsGenerator\EmbeddedConstants.g.cs Generated C# file path

The prefixed forms Meziantou_EmbeddedConstantsNamespace, Meziantou_EmbeddedConstantsClassName, Meziantou_EmbeddedConstantsClassVisibility, Meziantou_EmbeddedConstantsMemberVisibility, and Meziantou_EmbeddedConstantsOutputPath are also supported and take precedence over the shorter aliases.

EmbeddedConstant Metadata

Metadata Required Description
Kind ✔️ Text, Binary, or Both
Name Base name used for generated members

The forms EmbeddedConstantKind, Meziantou_EmbeddedConstantKind, EmbeddedConstantName, and Meziantou_EmbeddedConstantName are also supported for compatibility.

Naming

When Name is set, the value is converted to a valid PascalCase identifier and used as the member base name. Otherwise, the file name without extension is used. Invalid identifier characters are treated as word separators, and names that start with a digit are prefixed with _.

Text files append Text to the base name. Binary files append Bytes. Files marked as Both append both Text and Bytes.

Examples:

File Kind Members
hello-world.txt Text HelloWorldText
appsettings.Development.json Both AppsettingsDevelopmentText, AppsettingsDevelopmentBytes
logo.bin Binary LogoBytes

If two implicit names collide, the generator tries a path-based name. Remaining collisions are reported as MSBuild errors.

Text Encoding

Text files must be valid UTF-8. An optional UTF-8 BOM is ignored. Binary files are embedded as-is.

Text files larger than 1 MiB are rejected to avoid producing impractically large generated source. Binary files are emitted as byte arrays and should also be kept reasonably small.

MSBuild Errors

Id Description
MFECG0001 Embedded constants namespace is invalid
MFECG0002 Embedded constants class name is invalid
MFECG0003 Embedded constant kind is missing
MFECG0004 Embedded constant kind is invalid
MFECG0005 Embedded constant member name is duplicated
MFECG0006 Embedded constant file cannot be read
MFECG0007 Embedded constant text file is not valid UTF-8
MFECG0008 Embedded constant text file is too large
MFECG0009 Embedded constants visibility is invalid
There are no supported framework assets in this package.

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.2 51 8/16/2026
1.0.1 113 7/8/2026
1.0.0 109 7/6/2026