CppAst 0.25.0

dotnet add package CppAst --version 0.25.0
                    
NuGet\Install-Package CppAst -Version 0.25.0
                    
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="CppAst" Version="0.25.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CppAst" Version="0.25.0" />
                    
Directory.Packages.props
<PackageReference Include="CppAst" />
                    
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 CppAst --version 0.25.0
                    
#r "nuget: CppAst, 0.25.0"
                    
#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 CppAst@0.25.0
                    
#: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=CppAst&version=0.25.0
                    
Install as a Cake Addin
#tool nuget:?package=CppAst&version=0.25.0
                    
Install as a Cake Tool

CppAst.NET ci Coverage Status NuGet

<img align="right" width="160px" height="160px" src="https://raw.githubusercontent.com/xoofx/CppAst.NET/main/img/cppast.png">

CppAst provides a C/C++ parser for header files with access to a managed AST model, comments and macros for .NET.

Purpose

The target primary usage of this library is to serve as a simple foundation for domain oriented PInvoke/Interop codegen

Features

  • Compatible with net8.0
    • For netstandard2.0 use 0.14.0 version.
  • Uses Clang/libclang 21.1.8.x through ClangSharp
  • Parses in-memory C/C++ text and C/C++ files from disk
  • Supports C, C++ and Objective-C language modes via CppParserOptions.ParserKind
  • Simple managed AST model with declarations for namespaces, classes/structs/unions, Objective-C interfaces, enums, fields/global variables, functions/methods, typedefs/using aliases and include directives
  • Broad type system for primitive, record, enum, typedef, pointer, reference, array, function, block-function, qualified, template and unexposed/dependent types
  • C++ support for common class, inheritance, constructor/destructor, operator, conversion, friend, inline/final/defaulted/deleted, template and specialization metadata
  • Provides access to system/annotate attributes, optional token-level attributes (CppParserOptions.ParseTokenAttributes) and comment-based attributes (CppParserOptions.ParseCommentAttribute)
  • Provides access to attached comments, including Doxygen comments and parameter comment commands
  • Provides access to expressions for variable initializers and default parameter values (e.g. const int x = (1 + 2) << 1 exposes the initializer expression)
  • Provides function body source spans with CppParserOptions.ParseFunctionBodies (not a full statement-body AST)
  • Provides access to macro definitions, parameters and tokens via CppParserOptions.ParseMacros (default is false)
  • Provides target configuration helpers such as ConfigureForWindowsMsvc(...) and ParseSystemIncludes filtering for system headers

Documentation

Check the user guide documentation from the doc/ folder.

Usage Example

Setup

After installing the NuGet package, configure your project to select a platform RID via the RuntimeIdentifier property so the native libclang asset is restored:

  <PropertyGroup>
    
    <RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == '' AND '$(PackAsTool)' != 'true'">$(NETCoreSdkRuntimeIdentifier)</RuntimeIdentifier>
  </PropertyGroup>

Code

You can jump-start with the CppParser.Parse method:

// Parse C++ files
var compilation = CppParser.Parse(@"
enum MyEnum { MyEnum_0, MyEnum_1 };
void function0(int a, int b);
struct MyStruct { int field0; int field1;};
typedef MyStruct* MyStructPtr;
"
);
// Print diagnostic messages
foreach (var message in compilation.Diagnostics.Messages)
    Console.WriteLine(message);

// Print All enums
foreach (var cppEnum in compilation.Enums)
    Console.WriteLine(cppEnum);

// Print All functions
foreach (var cppFunction in compilation.Functions)
    Console.WriteLine(cppFunction);

// Print All classes, structs
foreach (var cppClass in compilation.Classes)
    Console.WriteLine(cppClass);

// Print All typedefs
foreach (var cppTypedef in compilation.Typedefs)
    Console.WriteLine(cppTypedef);

Prints the following result:

enum MyEnum {...}
void function0(int a, int b)
struct MyStruct { ... }
typedef MyStruct* MyStructPtr

Binaries

This library is distributed as a NuGet package NuGet

Known issues

CppAst is a lightweight model over libclang and intentionally does not expose every Clang cursor or statement node. Some known limitations are:

  • Function bodies are exposed as source spans when requested, not as a full statement AST.
  • Template/dependent/unexposed types are represented on a best-effort basis and may require inspecting CppUnexposedType, display names or diagnostics for advanced C++ constructs.
  • Token-level attributes are still available for compatibility but are obsolete; prefer system/annotate attributes when possible.
  • Type sizes and built-in aliases such as size_t follow the configured target triple/ABI.

License

This software is released under the BSD-Clause 2 license.

Credits

  • ClangSharp: .NET managed wrapper around Clang/libclang

The C++ project cppast serves similar purpose although CppAst.NET does not share API or any implementation details.

Author

Alexandre Mutel aka xoofx.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on CppAst:

Package Downloads
CppAst.CodeGen

CppAst.CodeGen is an extensible P/Invoke Code Generator from C++ to C# for .NET

CppPinvokeGenerator

CppPinvokeGenerator is a simple pinvoke generator based on CppAst to generate C# for C++

SharpRNA.Tools

SharpRNA tooling to generate DNA YAML from C headers

GitHub repositories (8)

Showing the top 8 popular GitHub repositories that depend on CppAst:

Repository Stars
mono/SkiaSharp
SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library. It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.
EgorBo/SimdJsonSharp
C# bindings for lemire/simdjson (and full C# port)
Librelancer/Librelancer
A re-implementation of Freelancer
amerkoleci/Vortice.Vulkan
Cross platform .NET bindings for Vulkan, VMA, SPIRV-Cross and shaderc
BepInEx/Il2CppInterop
A tool interoperate between CoreCLR and Il2Cpp at runtime
EvergineTeam/WebGPU.NET
This repository contains low-level bindings for WebGPU used in Evergine.
xoofx/NPlug
Develop VST3 audio native plugins with .NET
xoofx/CppAst.CodeGen
An extensible library providing C# PInvoke codegen from C/C++ files for .NET
Version Downloads Last Updated
0.25.0 95 6/7/2026
0.24.0 1,350 11/20/2025
0.23.1 1,394 5/2/2025
0.23.0 299 5/1/2025
0.22.0 753 4/30/2025
0.21.4 716 4/13/2025
0.21.3 339 4/11/2025
0.21.2 493 3/29/2025
0.21.1 4,411 11/13/2024
0.21.0 651 10/16/2024
0.20.2 1,384 8/20/2024
0.20.1 1,297 5/22/2024
0.20.0 13,130 5/19/2024
0.19.0 311 5/19/2024
0.18.0 604 5/12/2024
0.17.0 352 5/12/2024
0.16.0 629 4/9/2024
0.15.0 937 1/9/2024
0.14.0 1,719 10/14/2023
0.13.0 606 8/30/2023
Loading failed