Skip to content

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

@dadavadd

Description

@dadavadd

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 and 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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions