|
| 1 | +<?xml version="1.0" encoding="utf-8"?> |
| 2 | +<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
| 3 | + |
| 4 | + <!-- |
| 5 | +
|
| 6 | + We have a few requirements when computing trimming properties: |
| 7 | +
|
| 8 | + 1. We must give MAUI a change to set MtouchLink, which they do in Microsoft.Maui.Controls.iOS.targets |
| 9 | + 2. We must set SuppressTrimAnalysisWarnings before Microsoft.NET.ILLink.targets is included. |
| 10 | +
|
| 11 | + 1: Microsoft.Maui.Controls.iOS.targets is included like this: |
| 12 | + a) Sdks/Microsoft.NET.Sdk/Sdk/Sdk.targets |
| 13 | + b) Microsoft.CSharp.targets |
| 14 | + c) Microsoft.CSharp.CurrentVersion.targets |
| 15 | + d) Microsoft.Common.targets |
| 16 | + e) <project path>/obj/*.csproj.nuget.g.targets |
| 17 | + f) packages/microsoft.maui.controls.build.tasks/<version>/buildTransitive/net6.0-ios10.0/Microsoft.Maui.Controls.Build.Tasks.targets |
| 18 | + g) packages/microsoft.maui.controls.build.tasks/<version>/buildTransitive/Microsoft.Maui.Controls.Build.Tasks.targets |
| 19 | + h) packages/microsoft.maui.controls.build.tasks/<version>/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.Build.Tasks.targets |
| 20 | + i) packages/packages/microsoft.maui.controls.build.tasks/<version>/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.Build.Tasks.Before.targets |
| 21 | + j) packages/packages/microsoft.maui.controls.build.tasks/<version>/buildTransitive/net6.0-ios10.0/Microsoft.Maui.Controls.iOS.targets |
| 22 | +
|
| 23 | + 2: Microsoft.NET.ILLink.targets is included like this: |
| 24 | + a) Sdks/Microsoft.NET.Sdk/Sdk/Sdk.targets |
| 25 | + b) Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets |
| 26 | + c) packages/microsoft.net.illink.tasks/<version>/build/Microsoft.NET.ILLink.targets |
| 27 | +
|
| 28 | + * Microsoft.NET.Sdk.targets is loaded right after |
| 29 | + Microsoft.CSharp.targets, and Microsoft.NET.Sdk.targets doesn't |
| 30 | + provide any customization points, so we can't inject logic in |
| 31 | + Microsoft.NET.Sdk.targets before Microsoft.NET.ILLink.targets is |
| 32 | + loaded. |
| 33 | + * However, Microsoft.Common.targets has a few customization points |
| 34 | + that are loaded after build logic from NuGets is loaded (aka |
| 35 | + Microsoft.Maui.Controls.iOS.targets), of which |
| 36 | + CustomBeforeDirectoryBuildTargets and |
| 37 | + CustomAfterDirectoryBuildTargets seem to fit. I chose |
| 38 | + CustomAfterDirectoryBuildTargets because that makes it possible to |
| 39 | + set MtouchLink/LinkMode in Directory.Build.targets files if people |
| 40 | + wants to do so. |
| 41 | +
|
| 42 | + --> |
| 43 | + |
| 44 | + <!-- Since we know if we're building for a simulator or not, we can determine the default trimming behavior --> |
| 45 | + <PropertyGroup Condition="'$(TrimMode)' != ''"> |
| 46 | + <!-- If TrimMode is set, then that's the default link mode --> |
| 47 | + <_DefaultLinkMode>TrimMode</_DefaultLinkMode> |
| 48 | + </PropertyGroup> |
| 49 | + <PropertyGroup Condition="'$(TrimMode)' == ''"> |
| 50 | + <!-- Linking is always on for all assemblies when using NativeAOT - this is because we need to modify all assemblies in the linker for them to be compatible with NativeAOT --> |
| 51 | + <_DefaultLinkMode Condition="'$(_UseNativeAot)' == 'true'">Full</_DefaultLinkMode> |
| 52 | + |
| 53 | + <_DefaultLinkMode Condition="'$(_UseNativeAot)' != 'true' And '$(_PlatformName)' == 'macOS'">None</_DefaultLinkMode> <!-- Linking is off by default for macOS apps --> |
| 54 | + <_DefaultLinkMode Condition="'$(_UseNativeAot)' != 'true' And '$(_PlatformName)' == 'MacCatalyst' And '$(Configuration)' == 'Release'">SdkOnly</_DefaultLinkMode> <!-- Default linking is on for release builds for Mac Catalyst apps --> |
| 55 | + <_DefaultLinkMode Condition="'$(_UseNativeAot)' != 'true' And '$(_PlatformName)' == 'MacCatalyst' And '$(Configuration)' != 'Release'">None</_DefaultLinkMode> <!-- Default linking is off for non-release builds for Mac Catalyst apps --> |
| 56 | + <_DefaultLinkMode Condition="'$(_UseNativeAot)' != 'true' And '$(_PlatformName)' != 'macOS' And '$(_PlatformName)' != 'MacCatalyst' And '$(_SdkIsSimulator)' == 'true'">None</_DefaultLinkMode> <!-- Linking is off by default in the simulator --> |
| 57 | + <_DefaultLinkMode Condition="'$(_UseNativeAot)' != 'true' And '$(_PlatformName)' != 'macOS' And '$(_PlatformName)' != 'MacCatalyst' And '$(_SdkIsSimulator)' != 'true'">SdkOnly</_DefaultLinkMode> <!-- Linking is SdkOnly for iOS/tvOS/watchOS apps on device --> |
| 58 | + </PropertyGroup> |
| 59 | + <PropertyGroup> |
| 60 | + <_LinkMode Condition="'$(_LinkMode)' == '' And '$(_PlatformName)' == 'macOS'">$(LinkMode)</_LinkMode> |
| 61 | + <_LinkMode Condition="'$(_LinkMode)' == '' And '$(_PlatformName)' != 'macOS'">$(MtouchLink)</_LinkMode> |
| 62 | + <_LinkMode Condition="'$(_LinkMode)' == ''">$(_DefaultLinkMode)</_LinkMode> |
| 63 | + <_LinkMode Condition="'$(_LinkMode)' == '' And '$(_PlatformName)' == 'macOS'">None</_LinkMode> <!-- Linking is off by default for macOS apps --> |
| 64 | + <_LinkMode Condition="'$(_LinkMode)' == '' And '$(_PlatformName)' != 'macOS'">SdkOnly</_LinkMode> <!-- Default linking is SdkOnly for iOS/tvOS/watchOS apps --> |
| 65 | + |
| 66 | + <!-- TrimMode specifies what the linker will do with framework assemblies --> |
| 67 | + <TrimMode Condition="'$(_LinkMode)' == 'TrimMode'">$(TrimMode)</TrimMode> |
| 68 | + <TrimMode Condition="'$(_LinkMode)' == 'None'">copy</TrimMode> |
| 69 | + <TrimMode Condition="'$(_LinkMode)' == 'SdkOnly'">partial</TrimMode> |
| 70 | + <TrimMode Condition="'$(_LinkMode)' == 'Full'">full</TrimMode> |
| 71 | + <!-- For None link mode we also need to set TrimMode for all assemblies. This is done later --> |
| 72 | + </PropertyGroup> |
| 73 | + |
| 74 | + <PropertyGroup> |
| 75 | + <!-- |
| 76 | + With NativeAOT we want to suppress trim warnings coming from ILLink and enable them only for ILC when publishing. |
| 77 | + For this reason, in case of NativeAOT while publishing, we set SuppressTrimAnalysisWarnings to true by default and store the overwriten default in |
| 78 | + _OriginalSuppressTrimAnalysisWarnings property, which is later used to properly configure warning suppression for ILC. |
| 79 | + --> |
| 80 | + <_OriginalSuppressTrimAnalysisWarnings>$(SuppressTrimAnalysisWarnings)</_OriginalSuppressTrimAnalysisWarnings> |
| 81 | + <SuppressTrimAnalysisWarnings Condition="'$(_UseNativeAot)' == 'true'">true</SuppressTrimAnalysisWarnings> |
| 82 | + <!-- Otherwise suppress trimmer warnings unless we're trimming all assemblies --> |
| 83 | + <SuppressTrimAnalysisWarnings Condition="'$(SuppressTrimAnalysisWarnings)' == '' And '$(TrimMode)' == 'full'">false</SuppressTrimAnalysisWarnings> |
| 84 | + <SuppressTrimAnalysisWarnings Condition="'$(SuppressTrimAnalysisWarnings)' == '' And '$(PublishAot)' == 'true'">false</SuppressTrimAnalysisWarnings> |
| 85 | + <SuppressTrimAnalysisWarnings Condition="'$(SuppressTrimAnalysisWarnings)' == ''">true</SuppressTrimAnalysisWarnings> |
| 86 | + </PropertyGroup> |
| 87 | + |
| 88 | +</Project> |
0 commit comments