admin管理员组

文章数量:1122832

I have a WinUI3/WinAppSDK app built with .NET 9. I want to enable Native AOT and Trimming for it but i get a few warnings for the NuGet packages I use.

I have these in my CSProj file. Full version and the source code available here

<PublishTrimmed>true</PublishTrimmed>
<TrimMode>partial</TrimMode>
<SuppressTrimAnalysisWarnings>false</SuppressTrimAnalysisWarnings>
<TrimmerSingleWarn>false</TrimmerSingleWarn>
<ItemGroup>
    <TrimmerRootDescriptor Include="MyRoots.xml" />
</ItemGroup>

And I defined assembly names in that XML file such as this

<linker>
  <assembly fullname="CommunityToolkit.WinUI.UI.Controls.DataGrid" preserve="all" />
</linker>

But it's not suppressing the warnings or excluding the assemblies from trimming. I used the syntax defined here. I've tried many combinations but none of them seem to work. What am I doing wrong here? How are we supposed to use root descriptors?


Here are some of the warnings but they aren't related to the question. Because I'm looking for a way to use the root descriptors feature for trimming to instruct it not to trim certain assemblies, types and so on according to the official documentation.

ABI.System.Collections.Generic.IDictionary<K,V>.<tor>g__InitFallbackCCWVTableIfNeeded|10_0(): 'KAbi' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in 'ABI.System.Collections.Generic.IDictionaryMethods<K,KAbi,V,VAbi>'. The field 'WinRT.Marshaler<T>.AbiType' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.

CommunityToolkit.WinUI.Utilities.TypeHelper.GetPropertyOrIndexer(Type, String, Object[]&): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors', 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.PublicFields', 'DynamicallyAccessedMemberTypes.PublicNestedTypes', 'DynamicallyAccessedMemberTypes.PublicProperties', 'DynamicallyAccessedMemberTypes.PublicEvents' in call to 'System.Type.GetDefaultMembers()'. The parameter 'type' of method 'CommunityToolkit.WinUI.Utilities.TypeHelper.GetPropertyOrIndexer(Type, String, Object[]&)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.

Windows.Win32.PInvoke.CoCreateInstance(Guid&, Object, CLSCTX, Guid&, Object&): P/invoke method 'Windows.Win32.PInvoke.CoCreateInstance(Guid*, Object, CLSCTX, Guid*, Object&)' declares a parameter with COM marshalling. Correctness of COM interop cannot be guaranteed after trimming. Interfaces and interface members might be removed.

本文标签: cHow to use root descriptors trimming option in NETStack Overflow