Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 20, 2025

Trimming is only supported in .NET 6+, but most libraries must support .NET Standard 2.0 or .NET Framework. The documentation lacked guidance on this essential multi-targeting requirement.

Changes

  • New section: "Multi-targeting for trimming" added after "Enable library trim warnings"
    • Documents common multi-targeting patterns (netstandard2.0;net8.0 and net472;netstandard2.0;net8.0)
    • Shows conditional IsTrimmable setup using IsTargetFrameworkCompatible MSBuild function
    • Provides recommendations for library authors preparing trim-compatible libraries
    • Links to related breaking change documentation

Example

<PropertyGroup>
  <TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
  <IsTrimmable Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">true</IsTrimmable>
</PropertyGroup>

This enables IsTrimmable only for frameworks that support trimming (net6.0+) while avoiding warnings for .NET Standard and .NET Framework targets.

Fixes #36487

Original prompt

This section details on the original issue you should resolve

<issue_title>Prepare .NET libraries for trimming: Add multi-targeting H2 with our recommendations</issue_title>
<issue_description>
See this comment copied below

Finally, recently we've learned that multi-targeting is not only very common, but basically a must have when enabling trimming. (This is based on experience trying to make some NuGets trim compatible). I think the document should have a section about the multi-targeting and our recommendations around it. But the core point is that very few libraries will only target latest TFM. By far the most common case is either library targets netstandard2.0 or it multi-targets net472, netstandard2.0 and net6.0 (or some combination of these).


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

Comments on the Issue (you are @copilot in this section)

@sbomer Leaving a note here to mention the new behavior in the `true` part of https://learn.microsoft.com/dotnet/core/deploying/trimming/prepare-libraries-for-trimming. @sbomer I'm adding a breaking change notice that mentions multi-targeting: https://github.com//pull/36775. We still need a dedicated section in the general trimming docs though. When that's added, we should also link to it from the breaking change notice.

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: sbomer <787361+sbomer@users.noreply.github.com>
Co-authored-by: sbomer <787361+sbomer@users.noreply.github.com>
Copilot AI changed the title [WIP] Prepare .NET libraries for trimming with multi-targeting recommendations Add multi-targeting section to trimming documentation Nov 20, 2025
Copilot finished work on behalf of sbomer November 20, 2025 22:36
Copilot AI requested a review from sbomer November 20, 2025 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prepare .NET libraries for trimming: Add multi-targeting H2 with our recommendations

2 participants