A safe, idiomatic, Native-AOT-compatible managed wrapper over the native .NET hosting components
(hostfxr and nethost). Locate and load hostfxr, initialize host contexts, start the runtime, read
and write runtime properties, run managed apps, and load assemblies or resolve managed function pointers,
all from clean C#, on .NET 10, across Windows, Linux and macOS.
Everything goes through source-generated P/Invokes and unmanaged function pointers (the only managed→native
callback uses an [UnmanagedCallersOnly] trampoline), so the whole surface stays Native-AOT friendly. Native
strings are marshalled per-platform (char_t is UTF-16 on Windows, UTF-8 on Unix).
aerafaldev.github.io/HostFxrSharp — guides for locating and
loading hostfxr, host contexts, runtime properties, and loading assemblies / function pointers.
| Package | Version | Description |
|---|---|---|
| HostFxrSharp | Managed wrapper over hostfxr and nethost: locate/load the host, start the runtime, run apps, load assemblies and resolve function pointers. |
dotnet add package HostFxrSharpusing HostFxrSharp;
// Run a managed application through the native host — works the same on Windows, Linux and macOS.
using HostContext context = HostFxr.InitializeForCommandLine(["MyApp.dll", "--flag"]);
int exitCode = context.RunApp();Or locate hostfxr and get a native function pointer to a managed static method:
using HostFxrSharp;
string hostFxrPath = NetHost.GetHostFxrPath();
using HostContext context = HostFxr.InitializeForRuntimeConfig("MyComponent.runtimeconfig.json");
var loader = context.GetAssemblyFunctionPointerLoader();
nint entryPoint = loader.Load(
assemblyPath: "MyComponent.dll",
typeName: "MyComponent.Entry, MyComponent",
methodName: "Run",
signature: MethodSignature.UnmanagedCallersOnly);Issues and pull requests are welcome — see CONTRIBUTING.
MIT © Aerafal