-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Add multi-targeting sections to trimming and AOT documentation #50076
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: sbomer <[email protected]>
Co-authored-by: sbomer <[email protected]>
Co-authored-by: sbomer <[email protected]>
Co-authored-by: sbomer <[email protected]>
sbomer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Add a similar note for IsAotCompatible (alongside the existing docs for that option).
Co-authored-by: sbomer <[email protected]>
Added in 78f6612. The note directs users to apply the same multi-targeting guidance when using |
…ming Co-authored-by: sbomer <[email protected]>
Co-authored-by: sbomer <[email protected]>
Co-authored-by: sbomer <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
|
|
||
| ## Multi-targeting for trimming | ||
|
|
||
| When preparing libraries for trimming, if your library targets any framework earlier than `net6.0` (such as `netstandard2.0` or `net472`), you should also multi-target to `net6.0` to ensure that apps targeting `net6.0` or above get a version of your library that supports the trim analyzer. Additionally, consider including the latest .NET version to ensure your library is analyzed with the latest analyzer. Use the `IsTargetFrameworkCompatible` MSBuild function to conditionally enable `IsTrimmable` for `net6.0` and above: |
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing Oxford comma in the list. According to the Markdown writing style guidelines, you must use the Oxford comma in all lists. Change (such as \netstandard2.0` or `net472`)to(such as `netstandard2.0`, or `net472`)` to include the comma before "or".
|
|
||
| ### Multi-targeting for AOT compatibility | ||
|
|
||
| When preparing libraries for AOT compatibility, if your library targets any framework earlier than `net8.0` (such as `netstandard2.0` or `net472`), you should also multi-target to `net8.0` to ensure that apps targeting `net8.0` or above get a version of your library that supports the AOT analyzers. Additionally, consider including the latest .NET version to ensure your library is analyzed with the latest analyzer. Use the `IsTargetFrameworkCompatible` MSBuild function to conditionally enable `IsAotCompatible` for `net8.0` and above: |
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing Oxford comma in the list. According to the Markdown writing style guidelines, you must use the Oxford comma in all lists. Change (such as \netstandard2.0` or `net472`)to(such as `netstandard2.0`, or `net472`)` to include the comma before "or".
| |NETSDK1208|The target platform identifier {0} was not recognized. This is because MSBuildEnableWorkloadResolver is set to false which disables .NET SDK Workloads which is required for this identifier. Unset this environment variable or MSBuild property to enable workloads.| | ||
| |NETSDK1209|The current Visual Studio version does not support targeting {0} {1}. Either target {0} {2} or lower, or use Visual Studio version {3} or higher.| | ||
| |NETSDK1210|IsAotCompatible and EnableAotAnalyzer are not supported for the target framework. Consider multi-targeting to a supported framework to enable ahead-of-time compilation analysis, and set IsAotCompatible only for the supported frameworks. For example:<br>`<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', '{0}'))>true</IsAotCompatible>`| | ||
| |NETSDK1210|IsAotCompatible and EnableAotAnalyzer are not supported for the target framework. Consider multi-targeting to a supported framework to enable ahead-of-time compilation analysis, and set IsAotCompatible only for the supported frameworks. For example:<br>`<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))>true</IsAotCompatible>`| |
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing closing quotation mark in the XML example. The Condition attribute is not properly closed. Change:
<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))>true</IsAotCompatible>to:
<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">true</IsAotCompatible>Note the added " before the > closing the Condition attribute.
| |NETSDK1210|IsAotCompatible and EnableAotAnalyzer are not supported for the target framework. Consider multi-targeting to a supported framework to enable ahead-of-time compilation analysis, and set IsAotCompatible only for the supported frameworks. For example:<br>`<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))>true</IsAotCompatible>`| | |
| |NETSDK1210|IsAotCompatible and EnableAotAnalyzer are not supported for the target framework. Consider multi-targeting to a supported framework to enable ahead-of-time compilation analysis, and set IsAotCompatible only for the supported frameworks. For example:<br>`<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">true</IsAotCompatible>`| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Summary
The trim analyzer is only supported in .NET 6+, and AOT compatibility analysis is only supported in .NET 8+, but most libraries must support earlier target frameworks like .NET Standard 2.0 or .NET Framework. The documentation lacked guidance on this essential multi-targeting requirement.
Adds a concise "Multi-targeting for trimming" section to the trimming documentation that clarifies when libraries need to multi-target to
net6.0. If a library targets any framework earlier thannet6.0(such asnetstandard2.0ornet472), it should also multi-target tonet6.0to avoid gaps where apps targetingnet6.0or above would consume an older framework asset. Additionally, the documentation now recommends including the latest .NET version (net10.0) to ensure the library is analyzed with the latest analyzer. The section shows how to conditionally enableIsTrimmableusing theIsTargetFrameworkCompatibleMSBuild function.This enables
IsTrimmableonly for frameworks where the trim analyzer is supported (net6.0+) while avoiding warnings for .NET Standard, .NET Framework, and earlier .NET Core targets. The example demonstrates proper multi-targeting without gaps, ensuring that any app targeting net6.0 or above gets a library asset that supports the trim analyzer, while also benefiting from the latest analyzer improvements.Additionally, adds a "Multi-targeting for AOT compatibility" subsection to the Native AOT documentation with similar guidance for conditionally enabling
IsAotCompatiblein multi-targeted projects. Since AOT compatibility analysis was introduced in .NET 8, the AOT section targetsnet8.0and also recommends including the latest .NET version:Also updates the .NET SDK error list documentation to specify the correct target frameworks in the example code:
net6.0in the examplenet8.0in the exampleOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.