Annotate Vanara libraries for trimming
See original GitHub issueIt is possible to manually mark Vanara for Trimming by adding hints to the csproj of every project that uses it, but this is laborious and repetitive. For example, if using just Vanara.PInvoke.User32
in a net6 app, I would need to add the following to the csproj of each exe to enable trimming:
<ItemGroup>
<!-- trim Vanara.PInvoke.User32 and all of it's dependencies -->
<TrimmableAssembly Include="Vanara.Core" />
<TrimmableAssembly Include="Vanara.PInvoke.Gdi32" />
<TrimmableAssembly Include="Vanara.PInvoke.Kernel32" />
<TrimmableAssembly Include="Vanara.PInvoke.Shared" />
<TrimmableAssembly Include="Vanara.PInvoke.User32" />
</ItemGroup>
It would be more convenient if Vanara libraries are already pre-annotated for trimming, so this happens automatically. This can be done by adding the [AssemblyMetadata("IsTrimmable", "True")]
attribute to each Vanara assembly.
Additionally, it might be useful to annotate any functions which use reflection (if there are any) with RequiresUnreferencedCode
and/or DynamicallyAccessedMembers
, as appropriate, to give hints to the trimmer and produce better results/warnings.
See also
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:9 (6 by maintainers)
Top GitHub Comments
Great suggestions. I’ll look at including soon.
Over half of the COM interfaces in Vanara are extracted from C++ and do not have Type Library support. In the past, all COMWrapper generation only worked with typelibs. Maybe that will change, but I really doubt it. Let’s move this conversation to Discussion thread #341 which references this issue. This is a area that obviously needs more research and better support.