ImGui.NET icon indicating copy to clipboard operation
ImGui.NET copied to clipboard

Support NativeAOT static linking via .targets file with cimgui static library

Open dadavadd opened this issue 4 months ago • 0 comments

Hello,

It would be great if ImGui.NET provided optional support for NativeAOT-friendly builds, by including a small .targets file that allows static linking of the cimgui native library during Native AOT compilation.

According to Microsoft documentation on Native code interop with Native AOT, the <NativeLibrary> and <DirectPInvoke> MSBuild items can be used to enable direct static linking of native libraries into AOT-compiled applications:

<ItemGroup>
  <DirectPInvoke Include="cimgui" />
  <NativeLibrary Include="cimgui.lib" Condition="$(RuntimeIdentifier.StartsWith('win'))" />
  <NativeLibrary Include="libcimgui.a" Condition="!$(RuntimeIdentifier.StartsWith('win'))" />
</ItemGroup>

This is especially useful for internal tooling and menu overlays compiled into standalone native DLLs with ILCompiler (NativeAOT), where zero dependencies are desired and dynamic loading is discouraged or unavailable (e.g. in injected code or sandboxed environments).

A minimal .targets file that adds the static .lib/.a based on the RID would be enough. NuGet package consumers could opt-in to static linking when targeting NativeAOT.

Would you consider adding this?

Thanks!

dadavadd avatar Jun 21 '25 14:06 dadavadd