Disable Trimming For Entire Project/Assembly #95891
Replies: 2 comments 5 replies
-
The .NET team's recommendation is to switch to a serializer that is compatible with trimming. As you found out, the experience is going to be very unpleasant and the publish-time warnings generated for the reflection-based serializer will cause a lot of noise. You'll likely miss things due to the warning noise. Quoting from the docs: "If there are any trim warnings, the app should be thoroughly tested after trimming to ensure that there are no behavior changes." That said, if you set If you want to keep an assembly in it's entirety and trim everything else, leave |
Beta Was this translation helpful? Give feedback.
-
Writing here because I am a bit confused about trimming. Consider the following dependency graph, A is the root assembly; B and C are direct dependencies; X,Y and Z are transitive dependencies: graph LR
A-->B-->X
A-->C-->Y
C-->Z
style A fill:#ADF,stroke:#333,stroke-width:4px,color:#000
style B fill:#7F9,stroke:#333,stroke-width:4px,color:#000
style C fill:#7F9,stroke:#333,stroke-width:4px,color:#000
style X fill:#f9f,stroke:#333,stroke-width:4px,color:#000
style Y fill:#f9f,stroke:#333,stroke-width:4px,color:#000
style Z fill:#7F9,stroke:#333,stroke-width:4px,color:#000
I want to remove X and Y, because I am certain that they will not be needed. A, B, C and Z must remain. How can I trim assembly A for that to happen? I tried the following in <PropertyGroup>
<AssemblyName>A</AssemblyName>
<PublishTrimmed>True</PublishTrimmed>
<TrimMode>partial</TrimMode>
</PropertyGroup>
<ItemGroup>
<!-- these are the assemblies that will be analysed to be trimmed -->
<TrimmableAssembly Include="X" />
<TrimmableAssembly Include="Y" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="B" Version="1.0.0" />
<PackageReference Include="C" Version="1.0.0" />
</ItemGroup> |
Beta Was this translation helpful? Give feedback.
-
Since losing default constructors due to trimming causes alot of problems for deserializers and my workaround has been sprinkling
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(AnotherModel))]
all over the place.So I'm trying to isolate all my serializable types into a class library project and prevent trimming on that assembly as a whole. I thought changing TrimMode to partial on the console app then setting IsTrimmable to false on the class library would prevent it from being trimmed.
On the console app (that is compiled to a WebAssembly with Uno Boostrap) I added this to the *.csproj:
I added a AssemblyInfo.cs to the class library with this:
[assembly: AssemblyMetadata("IsTrimmable", "False")]
Being thorough I also added this to the class library's csproj:
I assume I'm misunderstanding the documentation. Is there a way to disable trimming as a whole for the class library while leaving it enabled in the console app?
Beta Was this translation helpful? Give feedback.
All reactions