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.45k stars 511 forks source link

.NET hide confusing messages from the trimmer #15295

Open rolfbjarne opened 2 years ago

rolfbjarne commented 2 years ago

A few linker messages are confusing:

We should look into rewording/hiding these for our use-case.

Romfos commented 1 year ago

What is workaround for that? 1) If you enable trimming - compile error: Optimizing assemblies for size failed. Optimization can be disabled by setting the PublishTrimmed property to false. 2) If you disable trimming - macOS projects must build with PublishTrimmed=true. Current value: false. Set 'LinkMode=None' instead to disable trimming for all assemblies. 3) If add <LinkMode>None</LinkMode> in csproj - I have error from first point

What is the right way to use it?

I don't care about app size. How can I just disable it or make it work?

.NET 7 + Empty project with signalr client

  <PropertyGroup>
    <TargetFramework>net7.0-macos</TargetFramework>
    <OutputType>Exe</OutputType>
    <ApplicationId>hidden</ApplicationId>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="7.0.9" />
    <PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
  </ItemGroup>

cc @rolfbjarne

rolfbjarne commented 1 year ago
  1. If you enable trimming - compile error: Optimizing assemblies for size failed. Optimization can be disabled by setting the PublishTrimmed property to false.

The fix is to investigate the compile error here. I tried creating a csproj with the signalr client and it built fine for me.

Can you get a binlog as described here: https://github.com/xamarin/xamarin-macios/wiki/Diagnosis#binary-build-logs?

Romfos commented 1 year ago

@rolfbjarne

this is demo repository: https://github.com/Romfos/test-dotent-macos

error: https://github.com/Romfos/test-dotent-macos/actions/runs/5749135585/job/15583371765

rolfbjarne commented 1 year ago

This is the error:

error MM0179: This version of Microsoft.macOS requires the macOS 13.3 SDK (shipped with Xcode 14.3). Either upgrade Xcode to get the required header files or use the dynamic registrar or set the managed linker behaviour to Link Platform or Link Framework SDKs Only in your project's Mac Build Options > Linker Behavior) (to try to avoid the new APIs).

The easiest way to fix this is to use a newer Xcode (14.3 in this case).

Romfos commented 1 year ago

@rolfbjarne

wow

thank you, it helped me

on: push

jobs:
  build:
    runs-on: macos-13
    steps:
      - uses: maxim-lobanov/setup-xcode@v1
        with:
          xcode-version: latest-stable

      - name: Setup .NET
        uses: actions/setup-dotnet@v3
        with:
          dotnet-version: 7.0.x

      - name: Check out repository
        uses: actions/checkout@v3

      - name: Install macos workload
        run: dotnet workload install macos

      - name: Build osx-x64
        run: dotnet publish -r osx-x64 ./MacAppSignalR/MacAppSignalR.csproj

probably we need a guide - how to make it work with github actions just make runs-on: macos-13 + dotnet workload install macos are not always enough

but still strange that it tells me: Optimizing assemblies for size failed. Optimization can be disabled by setting the PublishTrimmed property to false.

rolfbjarne commented 1 year ago

I've filed a dotnet/runtime issue for this: https://github.com/dotnet/runtime/issues/90607

rolfbjarne commented 1 year ago

The second message:

"Optimizing assemblies for size failed. Optimization can be disabled by setting the PublishTrimmed property to false."

has been reworded, so it now only says:

"Optimizing assemblies for size failed."

and thus this is at least partially done. Moving to .NET 9 for the first message.