-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
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
Steps to Reproduce
- Create .NET 6 iOS Binding Library
- 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`