Skip to content

Commit 4272a3b

Browse files
[release/6.0.4xx-xcode14.1] [dotnet] Ensure any trimmer components are restored properly. (#17252)
.NET 8 will load the ILLink component based on the target framework of the project file - so if .NET 8 is building a net7.0-ios app, the build will restore and use the ILLink component from .NET 7. There is a problem however: * The inclusion of the ILLink component is dpendent on the PublishTrimmed property - if PublishTrimmed is true, then the ILLink component is restored (which makes sense, why restore it if it's not going to be used?). * We always PublishTrimmed, because the linker must always be executed for our projects. So far so good - we can just always enable PublishTrimmed, right? * Nope, when building on Windows, we only enable PublishTrimmed when connected to a Mac, because that's where the ILLink target must be executed (and if we're not connected to a Mac, we can't run the ILLink target, and things fall apart - so just disable PublishTrimmed in that, since it won't work anyway). * Early on in the build we have no idea if we're connected to a Mac or not, which means we can only enable PublishTrimmed in a target, and not as an early-on default value. This is *way* to late for the ILLink component, which needs PublishTrimmed set quite early in the build process. * Fortunately, the ILLink inclusion is actually gated on a different variable (_IsTrimmingEnabled) - which is initialized from PublishTrimmed if it's not set. So the way out here is to set _IsTrimmingEnabled early enough, and now the ILLink component is included and restored. * The additional hurdle is that we need to set _IsTrimmingEnabled in our .NET 6 and .NET 7 workloads as well, it's not enough to set it in our .NET 8 workload (which isn't even loaded when building an earlier TFM). Backport of #17227 Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
1 parent 1a34f1d commit 4272a3b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

dotnet/targets/Xamarin.Shared.Sdk.props

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@
3939
<!-- Ref: https://github.com/xamarin/xamarin-macios/issues/16193 -->
4040
<!-- Ref: https://github.com/dotnet/sdk/issues/28419 -->
4141
<GenerateSatelliteAssembliesForCore Condition="'$(GenerateSatelliteAssembliesForCore)' == ''">true</GenerateSatelliteAssembliesForCore>
42+
43+
<!-- This will ensure any trimmer components are restored by the framework reference logic. As such it must happen before Microsoft.NET.Publish.targets is included.
44+
Ref:
45+
* https://github.com/dotnet/sdk/pull/29441
46+
* https://github.com/dotnet/sdk/blob/c5a58bc6c3eb2b236b314e6d17a89a537459890c/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets#L20-L21
47+
* https://github.com/dotnet/sdk/blob/c5a58bc6c3eb2b236b314e6d17a89a537459890c/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets#L102
48+
-->
49+
<_IsTrimmingEnabled>true</_IsTrimmingEnabled>
4250
</PropertyGroup>
4351

4452
<!-- Set the default RuntimeIdentifier if not already specified. -->

0 commit comments

Comments
 (0)