Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to build iOS Binding Library wrapping iOS Framework Native Reference #8000

Closed
ChangStar8 opened this issue Jun 13, 2022 · 7 comments
Closed
Labels
area-infrastructure CI, Maestro / Coherency, upstream dependencies/versions platform/iOS 🍎 t/bug Something isn't working

Comments

@ChangStar8
Copy link

Description

I am attempting to update a project from Xamarin.Forms to Maui, that uses a binding project to wrap an iOS .framework library. I am not able to reference my Xamarin iOS Binding library in the Maui App; I need to create a new iOS Binding Library that targets .NET 6 iOS. I have been having trouble referencing the iOS Binding Library from the Maui App.

I have created a minimal Objective-C Framework, and validated it by integrating it into a Xamarin binding project and Xamarin.Forms project, and it works as expected - I am able to call into the Objective-C iOS Framework code from the application C# code.

But, when I try to consume a .NET 6 iOS Binding Library that uses the same Objective-C iOS Framework, I am lost. Visual Studio 17.3.0 preview allows me to create an iOS Binding Library, but it does not allow me to add a Native Framework Reference (the project context UI exists but is a no-op when I click it). So, I have manually modifed the iOSBinding .csproj file to reference the iOS Framework similarly to how the Xamarin binding library (from attached 210383-testmauiframeworkbindingscsproj.txt):

<ItemGroup>
 <NativeReference Include="Native References/TestFramework.framework">
 <Kind>Framework</Kind>
 </NativeReference>
 </ItemGroup>

This seems to work, in that I can (supposedly) successfully build this iOSBinding project But, I get linker errors when I try to build the Maui App. The Maui App references the iOSBinding project via (from attached 210309-testmauiappcsproj.txt):

<ProjectReference Include="..\TestMauiFrameworkBindings\TestMauiFrameworkBindings.csproj" />

When I build the Maui App I get the following build errors (from attached 210310-build.log):

1>C:\Program Files\dotnet\packs\Microsoft.iOS.Windows.Sdk\15.4.303\tools\msbuild\iOS\Xamarin.iOS.Common.After.targets(327,3): warning MT1302: Could not extract the native library 'TestFramework.framework' from '/Users/r_dsdcompb/Library/Caches/Xamarin/mtbs/builds/TestMauiApp/694bb3adfa58e8cc00b59acf89a20a0c002608c09695ad5f70b5d9442fc8a3d7/obj/Debug/net6.0-ios/ios-arm64/linker-cache/TestFramework.framework.zip'. Please ensure the native library was properly embedded in the managed assembly (if the assembly was built using a binding project, the native library must be included in the project, and its Build Action must be 'ObjcBindingNativeLibrary').

...

1>C:\Program Files\dotnet\packs\Microsoft.iOS.Windows.Sdk\15.4.303\tools\msbuild\iOS\Xamarin.iOS.Common.After.targets(327,3): error MT0140: File '/Users/r_dsdcompb/Library/Caches/Xamarin/mtbs/builds/TestMauiApp/694bb3adfa58e8cc00b59acf89a20a0c002608c09695ad5f70b5d9442fc8a3d7/obj/Debug/net6.0-ios/ios-arm64/linker-cache/TestFramework.framework/TestFramework' is not a valid framework.
1>

...

1>C:\Program Files\dotnet\packs\Microsoft.iOS.Windows.Sdk\15.4.303\tools\msbuild\iOS\Xamarin.iOS.Common.After.targets(368,3): error MSB3371: The file "obj\Debug\net6.0-ios\ios-arm64\linked\Link.semaphore" cannot be created. Could not find a part of the path 'C:\Users\R_DSLC\source\FrameworkTest_ForGithub\TestMauiApp\TestMauiApp\obj\Debug\net6.0-ios\ios-arm64\linked\Link.semaphore'.

Following the error "Build Action must be 'ObjcBindingNativeLibrary'" I've attempted to use ObjcBindingNativeLibrary in lieu of NativeReference in my .csproj:

<ObjcBindingNativeLibrary Include="Native References/TestFramework.framework"/>

But now when I build, the compiler simply can't seem to get access to the framework folder:

Error CS1566 Error reading resource 'TestFramework.framework' -- 'Access to the path 'C:\Users\...\FrameworkTest_ForGithub\TestMauiApp\TestMauiFrameworkBindings\Native References\TestFramework.framework' is denied.' TestMauiFrameworkBindings

I've verified the folder path is valid and done everything I can think of to ensure that the folder is accessible (modifying it's security, running VS as administrator, etc.). As far as I can tell the folder is identical to the Xamarin binding project one (I can even reference that one directly) but I still can't get the iOS Binding Library project built.

So, I'm not sure what the core issue is but it seems like the compiler can't access my native iOS framework library no matter what I do. Are iOS Binding Libraries for frameworks currently supported in .NET 6? Is there a canonical example I could reference that I haven't been able to find?

The attached zip contains:
TestFramework - output of simple Xcode framework
TestXamarinApp - Working Xamarin app referencing iOS Xamarin Binding Library
TestMauiApp - Unsuccessful attempt at recreating TestXamarinApp in MAUI

FrameworkTest_ForGithub.zip

Steps to Reproduce

  1. Create .NET 6 iOS Binding Library
  2. Attempt to add Native Reference to iOS framework (via .csproj, VS UI is not hooked up it appears)

Result:
Using NativeReference build action fails to embed the framework
Using ObjcBindingNativeLibrary build action causes compiler to fail to access framework

Version with bug

6.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

All iOS versions

Did you find any workaround?

No

Relevant log output

NativeReference build action:

1>C:\Program Files\dotnet\packs\Microsoft.iOS.Windows.Sdk\15.4.303\tools\msbuild\iOS\Xamarin.iOS.Common.After.targets(327,3): warning MT1302: Could not extract the native library 'TestFramework.framework' from '/Users/r_dsdcompb/Library/Caches/Xamarin/mtbs/builds/TestMauiApp/694bb3adfa58e8cc00b59acf89a20a0c002608c09695ad5f70b5d9442fc8a3d7/obj/Debug/net6.0-ios/ios-arm64/linker-cache/TestFramework.framework.zip'. Please ensure the native library was properly embedded in the managed assembly (if the assembly was built using a binding project, the native library must be included in the project, and its Build Action must be 'ObjcBindingNativeLibrary').

...

1>C:\Program Files\dotnet\packs\Microsoft.iOS.Windows.Sdk\15.4.303\tools\msbuild\iOS\Xamarin.iOS.Common.After.targets(327,3): error MT0140: File '/Users/r_dsdcompb/Library/Caches/Xamarin/mtbs/builds/TestMauiApp/694bb3adfa58e8cc00b59acf89a20a0c002608c09695ad5f70b5d9442fc8a3d7/obj/Debug/net6.0-ios/ios-arm64/linker-cache/TestFramework.framework/TestFramework' is not a valid framework.
1>

...

1>C:\Program Files\dotnet\packs\Microsoft.iOS.Windows.Sdk\15.4.303\tools\msbuild\iOS\Xamarin.iOS.Common.After.targets(368,3): error MSB3371: The file "obj\Debug\net6.0-ios\ios-arm64\linked\Link.semaphore" cannot be created. Could not find a part of the path 'C:\Users\R_DSLC\source\FrameworkTest_ForGithub\TestMauiApp\TestMauiApp\obj\Debug\net6.0-ios\ios-arm64\linked\Link.semaphore'.

ObjcBindingNativeLibrary output:

`Error    CS1566    Error reading resource 'TestFramework.framework' -- 'Access to the path 'C:\Users\...\FrameworkTest_ForGithub\TestMauiApp\TestMauiFrameworkBindings\Native References\TestFramework.framework' is denied.'    TestMauiFrameworkBindings`
@ChangStar8 ChangStar8 added s/needs-verification Indicates that this issue needs initial verification before further triage will happen t/bug Something isn't working labels Jun 13, 2022
@ChangStar8
Copy link
Author

ChangStar8 commented Jun 13, 2022

Update: Some further investigation unearths the 'ObjcBindingNativeFramework' build action, which does seem to change the build process (it attempts to zip the framework) but using this fails as well. Intermittently I see either the zip step errors with code 255, or a generic 'can't create a binding resource package' error.

1>/Users/.../Library/Caches/Xamarin/XMA/SDKs/dotnet/dotnet /Users/.../Library/Caches/Xamarin/XMA/SDKs/dotnet/packs/Microsoft.iOS.Sdk/15.4.303/tools/lib/bgen/bgen.dll @/Users/.../Library/Caches/Xamarin/mtbs/builds/TestMauiFrameworkBindings/65621e44f73b826d5ae331e1a20e4ad2c5b619da94e25ce83922098501d49a8f/obj/Debug/net6.0-ios/response-file.rsp
1>/usr/bin/zip -r -y /Users/.../Library/Caches/Xamarin/mtbs/builds/TestMauiFrameworkBindings/65621e44f73b826d5ae331e1a20e4ad2c5b619da94e25ce83922098501d49a8f/obj/Debug/net6.0-ios/TestFramework.framework .
1>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\15.4.303\tools\msbuild\iOS\Xamarin.Shared.ObjCBinding.targets(117,3): error MSB6006: "zip" exited with code 255.

OR

/Users/.../Library/Caches/Xamarin/XMA/SDKs/dotnet/dotnet /Users/.../Library/Caches/Xamarin/XMA/SDKs/dotnet/packs/Microsoft.iOS.Sdk/15.4.303/tools/lib/bgen/bgen.dll @/Users/.../Library/Caches/Xamarin/mtbs/builds/TestMauiFrameworkBindings/15dcb2c7b3494d14f57d65b823cc5bbd44ff1d0568944d71a42d187d9c8286fd/obj/Debug/net6.0-ios/response-file.rsp
 1>/usr/bin/zip -r -y /Users/.../Library/Caches/Xamarin/mtbs/builds/TestMauiFrameworkBindings/15dcb2c7b3494d14f57d65b823cc5bbd44ff1d0568944d71a42d187d9c8286fd/obj/Debug/net6.0-ios/TestFramework.framework .
 1>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\15.4.303\tools\msbuild\iOS\Xamarin.Shared.targets(183,3): error MT7068: Can't create a binding resource package unless there are native references in the binding project.

@jfversluis jfversluis added area-tooling XAML & C# Hot Reload, XAML Editor, Live Visual Tree, Live Preview, Debugging platform/iOS 🍎 and removed s/needs-verification Indicates that this issue needs initial verification before further triage will happen labels Jun 14, 2022
@jfversluis
Copy link
Member

@rolfbjarne is this something you know more about?

@jfversluis jfversluis added area/upstream and removed area-tooling XAML & C# Hot Reload, XAML Editor, Live Visual Tree, Live Preview, Debugging labels Jun 14, 2022
@xtuzy
Copy link

xtuzy commented Jun 15, 2022

@ChangStar8
Copy link
Author

Thanks xtuzy for reaching out! Your example is binding a static library (.a) however which is not what I am looking for... I have gotten that to work via some example projects I've found floating around in github. I need to bind an iOS framework which is stored as a folder and as far as I can tell has some custom steps associated to package/zip the framework contents.

Right now, I am looking for some high-level signal that this is indeed possible. I have been digging into build diagnostics and the targets files and it looks like there is support for Frameworks (e.g. ObjcBindingNativeFramework) but I have not gotten things to work. I spent some time looking at the deltas between build diagnostics and artifacts of a successful Xamarin app build and a failed MAUI app build, I've made some slow progress but keep running into new walls. I think I can get the iOS Library Binding project to build correctly, comparing it with the output of the Xamarin iOS Binding project, but unfortunately not the MAUI app.

@xtuzy
Copy link

xtuzy commented Jun 15, 2022

Do you try not use MAUI app, try use net6-ios app to do? i found MAUI at Windows reference winodws native project have bug, it need reference by nuget -_-

@ChangStar8
Copy link
Author

xtuzy, I don't quite follow "try not use MAUI app, try use net6-ios app to do?" Do you mean the target framework? I'm currently targetting net6.0-ios:
<TargetFrameworks>net6.0-ios</TargetFrameworks>

@rolfbjarne
Copy link
Member

This is a duplicate of xamarin/xamarin-macios#15289, so I'm closing this issue.

@rolfbjarne rolfbjarne closed this as not planned Won't fix, can't repro, duplicate, stale Jun 16, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jul 16, 2022
@Eilon Eilon added area-infrastructure CI, Maestro / Coherency, upstream dependencies/versions and removed area/upstream labels May 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-infrastructure CI, Maestro / Coherency, upstream dependencies/versions platform/iOS 🍎 t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants