HexaGen 1.1.23
Prefix Reserveddotnet add package HexaGen --version 1.1.23
NuGet\Install-Package HexaGen -Version 1.1.23
<PackageReference Include="HexaGen" Version="1.1.23" />
<PackageVersion Include="HexaGen" Version="1.1.23" />
<PackageReference Include="HexaGen" />
paket add HexaGen --version 1.1.23
#r "nuget: HexaGen, 1.1.23"
#:package HexaGen@1.1.23
#addin nuget:?package=HexaGen&version=1.1.23
#tool nuget:?package=HexaGen&version=1.1.23
HexaGen
HexaGen is a comprehensive code generation toolkit for C# and C++ projects. It uses HexaGen.CppAst to parse C/C++ headers and automatically generates C# bindings and wrappers. HexaGen simplifies the process of integrating native libraries with C# applications by automating the creation of interop code.
✨ Features
- C# Bindings for C Libraries: Automatically generate C# bindings from C headers with support for functions, structs, enums, and callbacks
- C# Bindings for COM Libraries: Create C# bindings for COM interfaces and objects
- C++ to C Wrappers: Generate C wrappers around C++ libraries to facilitate C interop
- Flexible Configuration: JSON-based configuration system with inheritance and composition support
- Advanced Function Generation: Multiple parameter handling strategies including spans, refs, delegates, and default values
- Type Mapping: Configurable type mappings and conversions
- Extension Methods: Generate extension methods for improved API ergonomics
- Constants to Enums: Convert C preprocessor constants to strongly-typed C# enums
📁 Project Structure
- HexaGen - Main code generation tool and CLI
- HexaGen.Core - Core functionality and utilities for code generation
- HexaGen.Cpp2C - C++ to C wrapper generator
- HexaGen.Runtime - Runtime support library for generated code (multi-target: .NET 9/8/7/6, .NET Standard 2.0/2.1, .NET Framework 4.7.2, Android)
- HexaGen.Runtime.COM - Runtime support for COM interop (multi-target: .NET 9/8/7/6, .NET Standard 2.0/2.1, .NET Framework 4.7.2)
- HexaGen.Language - Language parsing and processing utilities
- HexaGen.Tests - Unit tests
- HexaGen.PerformanceTests - Performance benchmarks
🔧 Requirements
- .NET SDK 9.0 (or compatible version)
- Clang 17.0.4 or later (for parsing C/C++ headers)
- Visual Studio 2022 or later (recommended for development)
📦 Installation
NuGet Package
Install HexaGen via NuGet Package Manager:
dotnet add package HexaGen
Build from Source
Clone the Repository:
git clone https://github.com/HexaEngine/HexaGen.git cd HexaGenBuild the Project:
dotnet build
🚀 Usage
Basic Example
Create a configuration file (e.g., config.json):
{
"ApiName": "MyLibrary",
"Namespace": "MyLibrary.Generated",
"ImportType": "DllImport",
"GenerateExtensions": true
}
Generate C# bindings programmatically:
using HexaGen;
var config = CsCodeGeneratorConfig.Load("config.json");
var generator = new CsCodeGenerator(config);
generator.Generate("mylibrary.h", "Output");
⚙️ Configuration
HexaGen uses a JSON-based configuration system that supports:
- BaseConfig: Configuration inheritance from other files
- Type Mappings: Custom type conversions
- Function Rules: Advanced parameter transformation rules
- Constants to Enum: Convert preprocessor defines to enums
- Import Types: DllImport, LibraryImport, or delegates
Example configuration with inheritance:
{
"BaseConfig": {
"Url": "file://config.base.json",
"IgnoredProperties": ["IgnoredTypes"]
},
"ApiName": "MyAPI",
"Namespace": "MyAPI.Generated",
"ImportType": "LibraryImport"
}
C++ to C Generation
For generating C wrappers around C++ libraries:
using HexaGen.Cpp2C;
var config = Cpp2CGeneratorConfig.Load("cpp2c-config.json");
var generator = new Cpp2CGenerator(config);
generator.Generate("mylibrary.hpp", "Output");
🤝 Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes following the project's coding standards
- Add appropriate tests
- Submit a pull request
📜 License
HexaGen is licensed under the MIT License. See the LICENSE.txt file for details.
🔗 Links
- GitHub Repository
- NuGet Package
- HexaGen.CppAst - The underlying C++ parser (custom fork)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net9.0
- CommandLineParser (>= 2.9.1)
- HexaGen.Core (>= 1.1.11)
- HexaGen.Language (>= 1.1.4)
- Microsoft.CodeAnalysis.CSharp (>= 4.8.0)
- Newtonsoft.Json (>= 13.0.3)
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.1.23 | 182 | 12/19/2025 | |
| 1.1.22.1 | 192 | 12/19/2025 | |
| 1.1.22 | 216 | 12/19/2025 | |
| 1.1.20 | 130 | 11/1/2025 | |
| 1.1.19 | 179 | 10/21/2025 | |
| 1.1.15-rc30 | 278 | 3/3/2025 | |
| 1.1.15-rc20 | 163 | 12/8/2024 | |
| 1.1.14 | 197 | 11/4/2024 | |
| 1.1.13 | 168 | 11/2/2024 | |
| 1.1.12 | 154 | 11/2/2024 | |
| 1.1.11 | 124 | 10/25/2024 | |
| 1.1.10 | 383 | 10/24/2024 | |
| 1.1.9 | 148 | 10/24/2024 | |
| 1.1.9-rc3 | 136 | 10/14/2024 | |
| 1.1.9-rc2 | 133 | 10/14/2024 | |
| 1.1.9-rc11 | 145 | 10/17/2024 | |
| 1.1.9-rc1 | 138 | 10/14/2024 | |
| 1.1.8 | 155 | 10/13/2024 | |
| 1.1.7 | 175 | 10/10/2024 | |
| 1.1.6 | 166 | 10/9/2024 | |
| 1.1.5 | 210 | 9/16/2024 | |
| 1.1.5-unstable | 151 | 9/6/2024 | |
| 1.1.4 | 197 | 8/19/2024 | |
| 1.1.3 | 226 | 8/18/2024 | |
| 1.1.2 | 178 | 8/18/2024 | |
| 1.1.1 | 172 | 8/16/2024 | |
| 1.1.0 | 180 | 8/16/2024 | |
| 1.0.1 | 183 | 8/14/2024 | |
| 1.0.0 | 153 | 8/5/2024 |