.NET 8 and Trimming

In .NET 6, trimming worked pretty well, even if you’re assemblies weren’t annotated properly. In .NET 7 and now with .NET 8, things have changed, and trying to trim with the same project files and settings will cause everything to break.

If you want to get the old .NET 6 behavior, annotate your csproj files with these elements:


  <TrimMode>partial</TrimMode>
  <JsonSerializerIsReflectionEnabledByDefault>true</JsonSerializerIsReflectionEnabledByDefault>

Hoping this saves someone the hours I lost fussing around with this. Microsoft’s trimming guide is good, but doesn’t mention the json property, which is now false by default in .NET 8, instead of true.

0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments