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

Projects referencing xcframeworks don't build properly on Windows #10784

Closed
leonluc-dev opened this issue Mar 4, 2021 · 8 comments · Fixed by #18103
Closed

Projects referencing xcframeworks don't build properly on Windows #10784

leonluc-dev opened this issue Mar 4, 2021 · 8 comments · Fixed by #18103
Labels
external-xamarin-vs Issues affecting the Xamarin in Visual Studio and are not specific to Xamarin.iOS or Xamarin.Mac

Comments

@leonluc-dev
Copy link

leonluc-dev commented Mar 4, 2021

Steps to Reproduce

  1. Create a Xamarin.iOS or Objective-C binding project
  2. Add an xcframework as a native reference
  3. Try to build the project on Windows (with a connected Mac build server)

Expected Behavior

The project builds and the xcframework is found and embedded during the build process.

Actual Behavior

If a Xamarin.iOS project referencing a xcframework is built on Windows, the following error occurs:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Xamarin\iOS\Xamarin.Shared.targets(142,3): error : Universal.xcframework has an incorrect or unknown format and cannot be processed.

If a Objective-C binding referencing a xcframework is built on Windows, no error occurs, but the result is missing the expected xcframework (no .resources folder is created)

Environment

Microsoft Visual Studio Professional 2019
Version 16.9.0
VisualStudio.16.Release/16.9.0+31025.194
Microsoft .NET Framework
Version 4.8.03752

Installed Version: Professional

Visual C++ 2019   00435-60000-00000-AA141
Microsoft Visual C++ 2019

ASP.NET and Web Tools 2019   16.9.687.37626
ASP.NET and Web Tools 2019

ASP.NET Core Razor Language Services   16.1.0.2107702+c4adaa061f13292143de82a96c71341e50bc4032
Provides languages services for ASP.NET Core Razor.

ASP.NET Web Frameworks and Tools 2019   16.9.687.37626
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0   16.9.687.37626
Azure App Service Tools v3.0.0

Azure Functions and Web Jobs Tools   16.9.687.37626
Azure Functions and Web Jobs Tools

C# Tools   3.9.0-6.21124.20+db94f4cc8c78a7cd8cf9cfdae091158d2ba9d974
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Extensibility Message Bus   1.2.6 (master@34d6af2)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

IntelliCode Extension   1.0
IntelliCode Visual Studio Extension Detailed Info

Microsoft Azure Tools   2.9
Microsoft Azure Tools for Microsoft Visual Studio 2019 - v2.9.40218.1

Microsoft Continuous Delivery Tools for Visual Studio   0.4
Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE.

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager   2.1.113+g422d40002e.RR
Install client-side libraries easily to any web project

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards   1.0
Microsoft Visual C++ Wizards

Microsoft Visual Studio Tools for Containers   1.1
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Microsoft Visual Studio VC Package   1.0
Microsoft Visual Studio VC Package

Mono Debugging for Visual Studio   16.9.7 (df23ba6)
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager   5.9.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

ProjectServicesPackage Extension   1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

ResXManager   1.50.4063.0
Manage localization of all ResX-Based resources in one place. Shows all resources of a solution and let's you edit the strings and their localizations in a well-arranged data grid.

SQL Server Data Tools   16.0.62102.01130
Microsoft SQL Server Data Tools

TypeScript Tools   16.0.30201.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   3.9.0-6.21124.20+db94f4cc8c78a7cd8cf9cfdae091158d2ba9d974
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools   16.9.0-beta.21102.9+7ce7132f1459095e635194d09d6f73265352029a
Microsoft Visual F# Tools

Visual Studio Code Debug Adapter Host Package   1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Container Tools Extensions   1.0
View, manage, and diagnose containers within Visual Studio.

Visual Studio Tools for Containers   1.0
Visual Studio Tools for Containers

VisualStudio.DeviceLog   1.0
Information about my package

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

Xamarin   16.9.000.271 (d16-9@863670b)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   16.9.0.316 (remotes/origin/d16-9@fdbf64026)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates   16.9.68 (8e9b569)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK   11.2.0.21 (d16-9/93eab59)
Xamarin.Android Reference Assemblies and MSBuild support.
    Mono: 5e9cb6d
    Java.Interop: xamarin/java.interop/d16-9@d6d86b2
    ProGuard: Guardsquare/proguard/v7.0.1@912d149
    SQLite: xamarin/sqlite/3.34.1@daff8f4
    Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-9@9d8924d


Xamarin.iOS and Xamarin.Mac SDK   14.14.2.5 (3836759d4)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Build Logs

Example Project (If Possible)

VS bug #1290812

@leonluc-dev
Copy link
Author

A similar issue occurs when trying to build an app referencing a xcframework based binding project. The binding project is added using the 'side-card' method referencing the DLL and having the .resources folder in the same folder as the DLL.
This works on mac builds, but on Windows environments (connected to a mac build server) it seems the xcframework in the .resources folder is not processed by the tooling, which leads to linker errors.

@mandel-macaque mandel-macaque added the external-xamarin-vs Issues affecting the Xamarin in Visual Studio and are not specific to Xamarin.iOS or Xamarin.Mac label Mar 10, 2021
@mandel-macaque
Copy link
Member

Hello, this look like an issue with the xamarin extension on windows. I have tagged the issue accordingly so that it is reviewed by a Windows developer.

@mauroa
Copy link
Contributor

mauroa commented Mar 11, 2021

Hi @leonluc-dev,
The root cause of your issue looks related to the fact that since VS 16.9, there's a bug in VS that prevents iOS Binding projects to be built correctly in Windows. We already have a DevCom ticket about this issue, which has recently been fixed: https://developercommunity.visualstudio.com/t/building-xamarin-ios-binding-project-not-longer-wo/1361154?from=email&viewtype=all#T-ND1367334

As you could see in the ticket, there's also a workaround that you can apply and get the iOS Binding projects building again.
Please do:

  • Close all the VS instances
  • Go to your VS installation folder (usually C:\Program Files (x86)\Microsoft Visual Studio\2019<Version>)
  • Then go to MSBuild\Xamarin\iOS
  • Edit the file Xamarin.iOS.ObjCBinding.CSharp.After.props
  • Remove the following line from it an save: <Import Project="$(MSBuildThisFileDirectory)Xamarin.Messaging.Build.targets" Condition="Exists('$(MSBuildThisFileDirectory)Xamarin.Messaging.Build.targets') And '$(MessagingBuildTargetsImported)' != 'true'" />
  • Open VS and try again

Please let me know if after applying the workaround your issue goes away.
Thanks

@leonluc-dev
Copy link
Author

leonluc-dev commented Mar 12, 2021

@mauroa
While that workaround did fix the issue for static libraries (.a) and .framework bindings, it seems xcframework builds are still broken.
While for .a and .framework builds the native code can be embedded in the DLL, for xcframeworks the compiler is supposed to generate a smaller DLL and a separate .resources folder containing the xcframework and a manifest. The Xamarin.iOS/Mac app can then use the binding by referencing the dll while having the .resources folder in the same folder as the dll.

After applying the workaround and building a xcframework based binding on Windows the smaller dll seems properly generated but the resources folder seems broken: the xcframework is missing and the manifest file is empty.

Building the binding project on Mac and then using the resulting dll and resources folder in a Xamarin.iOS project on Windows doesn't work either. The Windows tooling does pick up the referenced dll but doesn't pick up the resources folder it's supposed to look for in the same folder, which causes native linking errors.

I've opened a ticket summarizing all xcframework related issues on DevCom: https://developercommunity.visualstudio.com/t/XamariniOS-support-for-xcframeworks-on/1368376

@brunck
Copy link

brunck commented Jul 1, 2021

@leonluc-dev
Copy link
Author

leonluc-dev commented Aug 5, 2021

An update on this issue.
After some testing it seems Visual Studio 16.10.4 on Windows can build apps that reference XCFramework based bindings (dll + resource folder) now. However, support for referencing xcframeworks directly as a native reference or building the XFramework based binding project itself is still broken.
(See https://developercommunity.visualstudio.com/t/XamariniOS-support-for-xcframeworks-on/1450178 )

The issue was marked as "Out of Scope" by the Visual Studio Team (which I do not agree with) so I don't know if this will get fixed anytime soon.

@leonluc-dev leonluc-dev reopened this Aug 5, 2021
@brunck
Copy link

brunck commented Aug 5, 2021

@leonluc-dev The link you provided doesn't work (at least for me, it says "you don't have access or it doesn't exist"). I can only see the ticket via the link I provided above.

@leonluc-dev
Copy link
Author

@leonluc-dev The link you provided doesn't work (at least for me, it says "you don't have access or it doesn't exist"). I can only see the ticket via the link I provided above.

Seems the id was changed since I first files the issue. I have changed the link and it should be working now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
external-xamarin-vs Issues affecting the Xamarin in Visual Studio and are not specific to Xamarin.iOS or Xamarin.Mac
Projects
None yet
4 participants