xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.49k stars 515 forks source link

net8 regression: cannot build appextensions on iOS without workaround #19037

Closed enclave-alistair closed 1 year ago

enclave-alistair commented 1 year ago

Steps to Reproduce

  1. Create an iOS app extension (set <IsAppExtension>true</IsAppExtension>).
  2. Add an owning app that loads the app extension.
  3. Build.

Expected Behavior

Build completes ok.

Actual Behavior

Receive a linker error:

ILLink : error IL1034: Root assembly 'Dotnet.Test.NetExtension, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have entry point. [/Volumes/External/git/fabric-test/src/Dotnet.Test.NetExtension/Dotnet.Test.NetExtension.csproj::TargetFramework=net8.0-ios]
/Users/alistairevans/.nuget/packages/microsoft.net.illink.tasks/8.0.0-rc.1.23419.4/build/Microsoft.NET.ILLink.targets(87,5): error NETSDK1144: Optimizing assemblies for size failed. Optimization can be disabled by setting the PublishTrimmed property to false. [/Volumes/External/git/fabric-test/src/Dotnet.Test.NetExtension/Dotnet.Test.NetExtension.csproj::TargetFramework=net8.0-ios]

I have to add the following Target to the extension project file to make it work:

<Target Name="_FixRootAssembly" AfterTargets="PrepareForILLink">
    <ItemGroup>
        <TrimmerRootAssembly Update="@(TrimmerRootAssembly)" Condition=" '%(TrimmerRootAssembly.RootMode)' == 'EntryPoint' " RootMode="Library" />
    </ItemGroup>
</Target>

This was inspired by what I think is a related issue: https://github.com/dotnet/linker/issues/3165

Environment

Only building from the command-line right now (no VS on this Mac); as much version information as possible attached.

Version information ``` dotnet version 8.0.100-rc.1.23463.5 dotnet workload list Installed Workload Id Manifest Version Installation Source -------------------------------------------------------------------------------- maui-maccatalyst 8.0.0-rc.1.9171/8.0.100-rc.1 SDK 8.0.100-rc.1 maui-ios 8.0.0-rc.1.9171/8.0.100-rc.1 SDK 8.0.100-rc.1 installed packages: ```

Build Logs

msbuild.binlog.zip

Example Project

Example project where this failure occurs is here: https://github.com/enclave-alistair/dotnet-ios-netextension/tree/without-trimming-workaround

Workaround is applied on main of that repo, the without-trimming-workaround branch fails to build.

rolfbjarne commented 1 year ago

I can reproduce this.