dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.7k stars 1.06k forks source link

iOS Binding library for XCFramework fails with dependant frameworks #36527

Open damiand2 opened 1 year ago

damiand2 commented 1 year ago

Description

Hi, I'm trying to create iOS binding library for google map utils (https://github.com/googlemaps/google-maps-ios-utils) so I did following steps on Mac machine:

  1. download xcframework for google map utils
  2. create maui project, add iOS binding library, add reference to xcframework from above
  3. add sharpie generated files
  4. reference binding project in main project
  5. build of main project fails with following error:
    Target _ComputeFrameworkFilesToPublish:
    /Users/damiandekoszczak/Projects/MauiMapBindingTest/MapUtilsBinding/bin/Debug/net7.0-ios/MapUtilsBinding.resources/GoogleMapsUtils.xcframework/ios-arm64_x86_64-simulator/GoogleMapsUtils.framework/GoogleMapsUtils : warning MT7091: The framework /Users/damiandekoszczak/Projects/MauiMapBindingTest/MapUtilsBinding/bin/Debug/net7.0-ios/MapUtilsBinding.resources/GoogleMapsUtils.xcframework/ios-arm64_x86_64-simulator/GoogleMapsUtils.framework is a framework of static libraries, and will not be copied to the app.
    GMps-6.0.1/Base/Frameworks/GoogleMapsBase.framework/GoogleMapsBase : error MT158: The file 'GMps-6.0.1/Base/Frameworks/GoogleMapsBase.framework/GoogleMapsBase' does not exist.
    GMps-6.0.1/Base/Frameworks/GoogleMapsBase.framework/GoogleMapsBase : error MT158:         
    GMps-6.0.1/Maps/Frameworks/GoogleMapsCore.framework/GoogleMapsCore : error MT158: The file 'GMps-6.0.1/Maps/Frameworks/GoogleMapsCore.framework/GoogleMapsCore' does not exist.
    GMps-6.0.1/Maps/Frameworks/GoogleMapsCore.framework/GoogleMapsCore : error MT158:         
    GMps-6.0.1/Maps/Frameworks/GoogleMaps.framework/GoogleMaps : error MT158: The file 'GMps-6.0.1/Maps/Frameworks/GoogleMaps.framework/GoogleMaps' does not exist.
    GMps-6.0.1/Maps/Frameworks/GoogleMaps.framework/GoogleMaps : error MT158:         

So I tried to add also those base frameworks but it changes nothing in build errors. Is this scenario supported? How can I build binding library for framework that depends on other frameworks, not installed on Mac (as those other frameworks are also iOS-only). Should I try to build a FAT library?

Steps to Reproduce

  1. clone project from GitHub (https://github.com/damiand2/MauiMapBindingTest)
  2. try to build main project

Link to public reproduction project repository

https://github.com/damiand2/MauiMapBindingTest

Version with bug

7.0.92

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

No response

Did you find any workaround?

not yet

Relevant log output

No response

rmarinho commented 1 year ago

This issue was moved to xamarin/xamarin-macios#18802

rolfbjarne commented 1 year ago

Reopening, since this is not an issue in xamarin-macios. I believe it's in NuGet or dotnet/sdk.

The important information is that the project builds if using TargetFramework (singular) instead of TargetFrameworks (plural). As far as I know, using the plural version with a single target framework should be the same as using the singular version.

Binlogs: binlogs.zip

I've attached a working binlog (using TargetFramework) and a failing binlog (using TargetFrameworks).

The difference is that the working build imports Xamarin.Build.Download.props (which comes from a transitively referenced NuGet), while the broken build doesn't.

Screenshot comparison:

Screenshot 2023-08-28 at 16 57 21

Screenshot 2023-08-28 at 16 55 48

Note how the condition to import Xamarin.Build.Download.props is different, the broken version has an additional condition on the target framework.

My theory is that this is early enough in the build for TargetFramework not to be set, thus the condition fails - one reason I believe this is because the Xamarin.Build.Download.targets file is imported just fine later on, with the exact same condition:

Screenshot 2023-08-28 at 17 01 56

rolfbjarne commented 1 year ago

@rmarinho can you transfer to dotnet/sdk? it doesn't look like I have permissions to do that.

rolfbjarne commented 1 year ago

@damiand2 if you approve and merge https://github.com/damiand2/MauiMapBindingTest/pull/1 the test project will compile successfully once this issue is fixed.

damiand2 commented 1 year ago

@rolfbjarne - ok, waiting for confirmation from @rmarinho

fdevillard commented 1 week ago

Any update on this issue?

I'm facing a similar one using:

<PackageReference Include="Microsoft.ML.OnnxRuntime" Version="1.19.2" />
<PackageReference Include="Microsoft.ML.OnnxRuntime.Managed" Version="1.19.2" />

where the build has the following warning and app crashes whenever the resource should be loaded:

obj/Debug/net8.0-ios/iossimulator-arm64/onnxruntime.xcframework.zip/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework/onnxruntime : warning MT7091: The framework obj/Debug/net8.0-ios/iossimulator-arm64/onnxruntime.xcframework.zip/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework is a framework of static libraries, and will not be copied to the app.

(on macOS, and afaik my build tools are now up to date, I've re-installed everything from scratch using VSCode)

rolfbjarne commented 1 week ago

Any update on this issue?

Does your problem go away if you use "TargetFramework" (singular) as opposed to "TargetFrameworks" (plural) in your csproj? If not, then you're experiencing a different issue (so please create a new issue for it).