Do not write glue code yourself!
Preserving all API data, NativeExposer generates glue codes automatically to host C# from C++, without NativeAOT or IPC:
- C#
 
class Program
{
    [Export]
    public Program() {}
    [Export]
    public void Hello() {
        Console.WriteLine("Hello, World");
    }
}- C++
 
clr::assert(clr::init("<dotnet-root>", "<runtimeconfig.json>"));
clr::assert(clr::load("<your-dll>"));
Program program;
program.Hello();
clr::close();- Install 
NativeExposer.Buildto system 
dotnet tool install -g NativeExposer.Build
It installs native-exposer build tool to your system.
- Add 
NativeExposerto csproj as dependency 
<PackageReference Include="NativeExposer" Version="1.0.0"/>
- Use custom builder to generate stubs
 
native-exposer <csproj> <output-path>
It generates CMakeLists.txt, lib.cxx and lib.h.
You can use this CMakeLists.txt from your CMake project as add_subdirectory or etc...
- Enjoy it!
 
- .NET 5 or above
 
- Cannot export properties
 - Broken when trimming or NativeAOT