diff --git a/docs/core/deploying/native-aot/index.md b/docs/core/deploying/native-aot/index.md index bb07bd14be2d8..2ff1b8d2c6bf7 100644 --- a/docs/core/deploying/native-aot/index.md +++ b/docs/core/deploying/native-aot/index.md @@ -107,6 +107,19 @@ The preceding configuration assigns a default of `true` to the following propert These analyzers help to ensure that a library is compatible with Native AOT. +### 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`), multi-target to `net8.0`. This ensures that apps targeting `net8.0` or above get a version of your library that supports the AOT analyzers. Also, include the latest .NET version so your library is analyzed with the latest analyzer. Use the `IsTargetFrameworkCompatible` MSBuild function to conditionally enable `IsAotCompatible` for `net8.0` and above: + +```xml + + netstandard2.0;net8.0;net10.0 + true + +``` + +For more information, see [Trimming may not be used with .NET Standard or .NET Framework](../../compatibility/sdk/8.0/trimming-unsupported-targetframework.md). + ## Native debug information By default, Native AOT publishing produces debug information in a separate file: diff --git a/docs/core/deploying/trimming/prepare-libraries-for-trimming.md b/docs/core/deploying/trimming/prepare-libraries-for-trimming.md index 8185473604f72..d3a450bb1b7d8 100644 --- a/docs/core/deploying/trimming/prepare-libraries-for-trimming.md +++ b/docs/core/deploying/trimming/prepare-libraries-for-trimming.md @@ -3,7 +3,7 @@ title: Prepare .NET libraries for trimming description: Learn how to prepare .NET libraries for trimming. author: sbomer ms.author: svbomer -ms.date: 06/12/2023 +ms.date: 11/20/2025 --- # Prepare .NET libraries for trimming @@ -90,6 +90,19 @@ Follow the preceding pattern for multiple libraries. To see trim analysis warnin * Even if there were no API changes. * Introducing trim analysis warnings is a breaking change when the library is used with `PublishTrimmed`. +## 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`), multi-target to `net6.0`. This ensures that apps targeting `net6.0` or above get a version of your library that supports the trim analyzer. Also, include the latest .NET version so your library is analyzed with the latest analyzer. Use the `IsTargetFrameworkCompatible` MSBuild function to conditionally enable `IsTrimmable` for `net6.0` and above: + +```xml + + netstandard2.0;net6.0;net10.0 + true + +``` + +For more information, see [Trimming may not be used with .NET Standard or .NET Framework](../../compatibility/sdk/8.0/trimming-unsupported-targetframework.md). + ## Resolve trim warnings The preceding steps produce warnings about code that might cause problems when used in a trimmed app. The following examples show the most common warnings with recommendations for fixing them. diff --git a/docs/core/tools/sdk-errors/index.md b/docs/core/tools/sdk-errors/index.md index 2503ee2c236c2..cf4e02e65e40b 100644 --- a/docs/core/tools/sdk-errors/index.md +++ b/docs/core/tools/sdk-errors/index.md @@ -370,7 +370,7 @@ This list is a complete list of the errors that you might get from the .NET SDK |NETSDK1207|Ahead-of-time compilation is not supported for the target framework.| |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:
`true`| |NETSDK1211|EnableSingleFileAnalyzer is not supported for the target framework. Consider multi-targeting to a supported framework to enable single-file analysis, and set EnableSingleFileAnalyzer only for the supported frameworks. For example:
`true`| -|NETSDK1212|IsTrimmable and EnableTrimAnalyzer are not supported for the target framework. Consider multi-targeting to a supported framework to enable trimming, and set IsTrimmable only for the supported frameworks. For example:
`true`| +|NETSDK1212|IsTrimmable and EnableTrimAnalyzer are not supported for the target framework. Consider multi-targeting to a supported framework to enable trimming, and set IsTrimmable only for the supported frameworks. For example:
`true`| |NETSDK1213|Targeting .NET 8.0 or higher in Visual Studio 2022 17.7 is not supported.|