Embedder is a command-line utility that embeds files as byte arrays in C# code. It generates two separate files to improve IDE performance when working with large embedded resources:
- Implementation file (
.Impl.cs) - contains private byte arrays with file data - Definition file (
.cs) - contains lightweight public accessors usingReadOnlySpan<byte>
- Split implementation and definition for better usability
- Support for multiple embedded files in a single command
- Customizable class name, namespace, and output paths
- Clear documentation in generated code
You can install Embedder in several ways:
-
Download pre-built AOT binaries:
- Visit GitHub Releases and download the latest version
-
Build from source:
git clone https://github.com/dreagledr/Embedder.git cd Embedder dotnet build -c Release -
Build AOT version:
git clone https://github.com/dreagledr/Embedder.git cd Embedder dotnet publish -c Release
Embedder [options] <file1:field1> [file2:field2] ...-f, --file <file:field>- Add a file to embed (can be used multiple times)-o, --output <path>- Output file path for definitions (default:EmbeddedFiles.cs)-i, --impl-output <path>- Output file path for implementation (default:EmbeddedFiles.Impl.cs)-c, --class <name>- Class name for the generated code (default:EmbeddedResources)-n, --namespace <name>- Namespace for the generated code (default:Embedded)
# Basic usage with two files
Embedder image.png:ImageData style.css:StyleContent -o Resources.cs
# Advanced usage with custom class name and namespace
Embedder --file logo.png:Logo --file config.json:ConfigData --class AppResources --namespace MyApp.Resources --output AppResources.cs
# Using shorthand options
Embedder -f logo.png:Logo -f data.bin:BinaryData -c Resources -n MyApp -o Res.cs -i Res.Impl.csResources.Impl.cs (implementation - contains the actual data):
// <auto-generated>
// This code was generated by Embedder (implementation part)
// Contains private storage for embedded resources
// Do not modify this file manually
using System;
namespace MyApp
{
public static partial class Resources
{
// Embedded file: logo.png
private static readonly byte[] _Logo = new byte[12345] {
0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D,
// ... thousands of bytes ...
};
// Embedded file: data.bin
private static readonly byte[] _BinaryData = new byte[56789] {
0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x00, 0x11, 0x22, 0x33,
// ... thousands of bytes ...
};
}
}Resources.cs (definition - lightweight accessors):
// <auto-generated>
// This code was generated by FileEmbedder (definition part)
// Contains public accessors for embedded resources
// Do not modify this file manually
using System;
namespace MyApp
{
public static partial class Resources
{
/// <summary>
/// Gets the embedded file content as byte array
/// </summary>
public static ReadOnlySpan<byte> Logo => _Logo;
/// <summary>
/// Gets the embedded file content as byte array
/// </summary>
public static ReadOnlySpan<byte> BinaryData => _BinaryData;
}
}- Improved IDE Performance: The large implementation file is separated from the lightweight definition file, allowing IDEs to index only the small definition file
- Clean API: Consumers see only the public accessors without being overwhelmed by implementation details
- Maintainability: Clear separation of concerns makes the generated code easier to maintain
Embedder - это консольная утилита, которая встраивает файлы как массивы байтов в C# код. Она генерирует два отдельных файла для удоюства при работе с большими встроенными ресурсами:
- Файл реализации (
.Impl.cs) - содержит приватные массивы байтов с данными файлов - Файл определения (
.cs) - содержит легковесные публичные аксессоры с использованиемReadOnlySpan<byte>
- Разделение реализации и определения для улучшения производительности IDE
- Поддержка нескольких встраиваемых файлов в одной команде
- Настройка имени класса, пространства имен и путей вывода
- Четкая документация в сгенерированном коде
Вы можете установить Embedder несколькими способами:
-
Скачать готовые AOT бинарники:
- Посетите GitHub Releases и скачайте последнюю версию
-
Собрать из исходников:
git clone https://github.com/dreagledr/Embedder.git cd Embedder dotnet build -c Release -
Собрать AOT версию (для простоты переноса):
git clone https://github.com/dreagledr/Embedder.git cd Embedder dotnet publish -c Release
Embedder [опции] <файл1:поле1> [файл2:поле2] ...-f, --file <файл:поле>- Добавить файл для встраивания (можно использовать несколько раз)-o, --output <путь>- Путь к файлу вывода для определений (по умолчанию:EmbeddedFiles.cs)-i, --impl-output <путь>- Путь к файлу вывода для реализации (по умолчанию:EmbeddedFiles.Impl.cs)-c, --class <имя>- Имя класса для сгенерированного кода (по умолчанию:EmbeddedResources)-n, --namespace <имя>- Пространство имен для сгенерированного кода (по умолчанию:Embedded)
# Базовое использование с двумя файлами
Embedder image.png:ImageData style.css:StyleContent -o Resources.cs
# Расширенное использование с пользовательским именем класса и пространством имен
Embedder --file logo.png:Logo --file config.json:ConfigData --class AppResources --namespace MyApp.Resources --output AppResources.cs
# Использование коротких опций
Embedder -f logo.png:Logo -f data.bin:BinaryData -c Resources -n MyApp -o Res.cs -i Res.Impl.csResources.Impl.cs (реализация - содержит фактические данные):
// <auto-generated>
// This code was generated by Embedder (implementation part)
// Contains private storage for embedded resources
// Do not modify this file manually
using System;
namespace MyApp
{
public static partial class Resources
{
// Embedded file: logo.png
private static readonly byte[] _Logo = new byte[12345] {
0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D,
// ... тысячи байтов ...
};
// Embedded file: data.bin
private static readonly byte[] _BinaryData = new byte[56789] {
0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x00, 0x11, 0x22, 0x33,
// ... тысячи байтов ...
};
}
}Resources.cs (определение - легковесные аксессоры):
// <auto-generated>
// This code was generated by FileEmbedder (definition part)
// Contains public accessors for embedded resources
// Do not modify this file manually
using System;
namespace MyApp
{
public static partial class Resources
{
/// <summary>
/// Gets the embedded file content as byte array
/// </summary>
public static ReadOnlySpan<byte> Logo => _Logo;
/// <summary>
/// Gets the embedded file content as byte array
/// </summary>
public static ReadOnlySpan<byte> BinaryData => _BinaryData;
}
}- Улучшенная производительность IDE: Большой файл реализации отделен от легковесного файла определения, что позволяет IDE индексировать только небольшой файл определения
- Чистый API: Потребители видят только публичные аксессоры без перегрузки деталями реализации
- Поддерживаемость: Четкое разделение ответственности делает сгенерированный код проще для поддержки
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License
Copyright (c) [2026] [dreagledr]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.