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

Build from Visual Studio 2022 17.8.0 Preview 3.0 paired to Mac failing if using a Nuget package with xcframework reference #19173

Closed
skha83 opened this issue Oct 12, 2023 · 8 comments · Fixed by #19227
Assignees
Labels
bug If an issue is a bug or a pull request a bug fix regression The issue or pull request is a regression
Milestone

Comments

@skha83
Copy link

skha83 commented Oct 12, 2023

Might be something similar to #19152 or at least the second comment in that issue.

Steps to Reproduce

  1. Create new Blank Maui App from Template
  2. Add Nuget Package References to a package containig a xcframework in this case Cognex.cmbSDK.Maui which is a barcode scanner
  3. Connect to Mac
  4. Deploy to real device or simulator

Expected Behavior

App builds and deploys to device without problems

Actual Behavior

The build fails.
This Nuget package and build worked on previous preview versions and RC1 of .NET 8.0. I have tried with both Xcode 14.3 and Xcode 15 on the remote Mac.

The build fails with the following warning and errors. The first warning is probably what generate the last error as it can't find symbol references because of the warning. I have checked that the file is located in the given folder.
Warning in the start of the build:

1>  Task "ResolveNativeReferences"
1>    ResolveNativeReferences: 2023-10-12T09:52:42.4589736+02:00 - Started
1>    ResolveNativeReferences: 2023-10-12T09:52:42.4589736+02:00 - Initializing
1>    [xma][info]: Trying to get a Build Connection...
1>    [xma][info]: Sending Request Xamarin.Messaging.GetActiveAgentsMessage to topic xma/agents
1>    [xma][info]: Received Response of Xamarin.Messaging.GetActiveAgentsMessage to topic build180165484SrenK/+/xma/agents
1>    [xma][info]: Sending Request Xamarin.Messaging.GetActiveAgentsMessage to topic xma/agents
1>    [xma][info]: Received Response of Xamarin.Messaging.GetActiveAgentsMessage to topic build180165484SrenK/+/xma/agents
1>    [xma][info]: The Build Connection 'Xamarin.Messaging.Build.Client.BuildConnection.18016' is active and ready to use
1>    [xma][info]: Sending Request Xamarin.Messaging.GetActiveAgentsMessage to topic xma/agents
1>    [xma][info]: Received Response of Xamarin.Messaging.GetActiveAgentsMessage to topic build180165484SrenK/+/xma/agents
1>    ResolveNativeReferences: 2023-10-12T09:52:42.6284209+02:00 - Initialized
1>    ResolveNativeReferences: 2023-10-12T09:52:42.6441381+02:00 - Determining the modified inputs that should be copied to the Mac (181 files)
1>    [xma][info]: Determining task items to copy to the server for 'MauiTestApp'...
1>    [xma][info]: Sending Request Xamarin.Messaging.Build.Contracts.CompareItemsMessage to topic xvs/build/16.4.8968-net8-rc2/compare-items
1>    [xma][info]: Received Response of Xamarin.Messaging.Build.Contracts.CompareItemsMessage to topic build180165484SrenK/+/xvs/build/16.4.8968-net8-rc2/compare-items
1>    [xma][info]: There's no new items to copy to the server for 'MauiTestApp'
1>    ResolveNativeReferences: 2023-10-12T09:52:43.3798444+02:00 - Serializing inputs
1>    ResolveNativeReferences: 2023-10-12T09:52:43.3950558+02:00 - Executing
1>    [xma][info]: Starting remote task execution for 'MauiTestApp': Xamarin.MacDev.Tasks.ResolveNativeReferences
1>    [xma][info]: Sending Request Xamarin.Messaging.Build.Contracts.ExecuteTaskMessage to topic xvs/build/16.4.8968-net8-rc2/execute-task/MauiTestApp/0d88230002fResolveNativeReferences
1>    [xma][info]: Received Response of Xamarin.Messaging.Build.Contracts.ExecuteTaskMessage to topic build180165484SrenK/+/xvs/build/16.4.8968-net8-rc2/execute-task/MauiTestApp/0d88230002fResolveNativeReferences
1>    ResolveNativeReferences: 2023-10-12T09:52:43.6653202+02:00 - Logging messages
1>    C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\16.4.8968-net8-rc2\tools\msbuild\iOS\Xamarin.Shared.targets(138,3): warning : The file 'c:/nuget/cognex.cmbsdk.maui/2.7.0/buildTransitive/../lib/net6.0-ios16.0/cmbSDK.xcframework/Info.plist' does not exist.
1>    ResolveNativeReferences: 2023-10-12T09:52:43.6653202+02:00 - Deserializing outputs
1>    ResolveNativeReferences: 2023-10-12T09:52:43.6653202+02:00 - Creating output items
1>    ResolveNativeReferences: 2023-10-12T09:52:43.6653202+02:00 - Finished
1>  Done executing task "ResolveNativeReferences".

Error in the end of the build:

1>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\16.4.8968-net8-rc2\tools\msbuild\iOS\Xamarin.Shared.targets(138,3): warning : The file 'c:/nuget/cognex.cmbsdk.maui/2.7.0/buildTransitive/../lib/net6.0-ios16.0/cmbSDK.xcframework/Info.plist' does not exist.
1>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\16.4.8968-net8-rc2\targets\Xamarin.Shared.Sdk.targets(1556,3): error : clang++ exited with code 1:
1>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\16.4.8968-net8-rc2\targets\Xamarin.Shared.Sdk.targets(1556,3): error : ld: warning: ignoring duplicate libraries: '-lSystem.Globalization.Native', '-lSystem.IO.Compression.Native', '-lSystem.Native', '-lSystem.Net.Security.Native', '-lSystem.Security.Cryptography.Native.Apple', '-lcompression', '-lmono-component-debugger', '-lmono-component-diagnostics_tracing', '-lmono-component-hot_reload', '-lmono-component-marshal-ilgen', '-lmonosgen-2.0', '-lxamarin-dotnet-debug'
1>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\16.4.8968-net8-rc2\targets\Xamarin.Shared.Sdk.targets(1556,3): error : ld: Undefined symbols:
1>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\16.4.8968-net8-rc2\targets\Xamarin.Shared.Sdk.targets(1556,3): error :   _MWB_cleanupLib, referenced from:
1>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\16.4.8968-net8-rc2\targets\Xamarin.Shared.Sdk.targets(1556,3): error :       <initial-undefines>
1>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\16.4.8968-net8-rc2\targets\Xamarin.Shared.Sdk.targets(1556,3): error :   _MWB_createRegionsFromTiles, referenced from:
1>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\16.4.8968-net8-rc2\targets\Xamarin.Shared.Sdk.targets(1556,3): error :       <initial-undefines>
1>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\16.4.8968-net8-rc2\targets\Xamarin.Shared.Sdk.targets(1556,3): error :   _MWB_disableCode, referenced from:
1>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\16.4.8968-net8-rc2\targets\Xamarin.Shared.Sdk.targets(1556,3): error :       <initial-undefines>
1>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\16.4.8968-net8-rc2\targets\Xamarin.Shared.Sdk.targets(1556,3): error :   _MWB_disableFlag, referenced from:
1>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\16.4.8968-net8-rc2\targets\Xamarin.Shared.Sdk.targets(1556,3): error :       <initial-undefines>
1>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\16.4.8968-net8-rc2\targets\Xamarin.Shared.Sdk.targets(1556,3): error :   _MWB_disableSubcode, referenced from:
1>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\16.4.8968-net8-rc2\targets\Xamarin.Shared.Sdk.targets(1556,3): error :       <initial-undefines>
1>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\16.4.8968-net8-rc2\targets\Xamarin.Shared.Sdk.targets(1556,3): error :   _MWB_enableCode, referenced from:
1>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\16.4.8968-net8-rc2\targets\Xamarin.Shared.Sdk.targets(1556,3): error :       <initial-undefines>
1>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\16.4.8968-net8-rc2\targets\Xamarin.Shared.Sdk.targets(1556,3): error :   _MWB_enableFlag, referenced from:
1>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\16.4.8968-net8-rc2\targets\Xamarin.Shared.Sdk.targets(1556,3): error :       <initial-undefines>
1>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\16.4.8968-net8-rc2\targets\Xamarin.Shared.Sdk.targets(1556,3): error :   _MWB_enableSubcode, referenced from:
1>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\16.4.8968-net8-rc2\targets\Xamarin.Shared.Sdk.targets(1556,3): error :       <initial-undefines>
1>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\16.4.8968-net8-rc2\targets\Xamarin.Shared.Sdk.targets(1556,3): error :   _MWB_getActiveCodes, referenced from:
1>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\16.4.8968-net8-rc2\targets\Xamarin.Shared.Sdk.targets(1556,3): error :       <initial-undefines>
1>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\16.4.8968-net8-rc2\targets\Xamarin.Shared.Sdk.targets(1556,3): error :   _MWB_getActive
1>    1 Warning(s)
1>    1 Error(s)

Environment

Version information
Microsoft Visual Studio Professional 2022
Version 17.8.0 Preview 3.0
VisualStudio.17.Preview/17.8.0-pre.3.0+34205.153
Microsoft .NET Framework
Version 4.8.04084

Installed Version: Professional

ASP.NET and Web Tools   17.8.339.8044
ASP.NET and Web Tools

Azure App Service Tools v3.0.0   17.8.339.8044
Azure App Service Tools v3.0.0

C# Tools   4.8.0-3.23504.4+81d9274600db701a8b08ed8af3fd6b00a775cc33
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Extensibility Message Bus   1.4.39 (main@e8108eb)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

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

Mono Debugging for Visual Studio   17.8.17 (957fbed)
Support for debugging Mono processes with Visual Studio.

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

Razor (ASP.NET Core)   17.8.3.2350401+8de09384414b0f850b29991342b4c40c423a8b40
Provides languages services for ASP.NET Core Razor.

StylerPackage Extension   1.0
StylerPackage Visual Stuido Extension Detailed Info

TypeScript Tools   17.0.20920.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   4.8.0-3.23504.4+81d9274600db701a8b08ed8af3fd6b00a775cc33
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   17.8.0-beta.23475.2+10f956e631a1efc0f7f5e49c626c494cd32b1f50
Microsoft Visual F# Tools

Visual Studio Extension for SpecFlow   1.0
Visual Studio extension for working with SpecFlow projects and Gherkin feature files.

Visual Studio IntelliCode   2.2
AI-assisted development for Visual Studio.

VisualStudio.DeviceLog   1.0
Information about my package

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

VSPackage Extension   1.0
VSPackage Visual Studio Extension Detailed Info

Xamarin   17.8.0.147 (d17-8@592be68)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   17.8.3.6 (remotes/origin/d17-8@eccf46a291)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates   17.8.16 (830b56a)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK   13.2.2.0 (d17-5/45b0e14)
Xamarin.Android Reference Assemblies and MSBuild support.
    Mono: d9a6e87
    Java.Interop: xamarin/java.interop/d17-5@149d70fe
    SQLite: xamarin/sqlite/3.40.1@68c69d8
    Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-5@ca1552d


Xamarin.iOS and Xamarin.Mac SDK   16.4.0.18 (9d266025e)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Build Logs

Output-Build.txt
https://github.com/skha83/MauiIosError/blob/main/Output-Build.txt

Example Project (If Possible)

https://github.com/skha83/MauiIosError

@rolfbjarne rolfbjarne added bug If an issue is a bug or a pull request a bug fix regression The issue or pull request is a regression labels Oct 13, 2023
@rolfbjarne rolfbjarne added this to the .NET 8 milestone Oct 13, 2023
@rolfbjarne
Copy link
Member

OK, I can reproduce, and I'll try to fix this next week.

@philipag
Copy link

@rolfbjarne I see you fixed this. Is it possible to install this updated build task on top of the latest VS 17.8.0 Preview 3 so that I can continue development?

@rolfbjarne
Copy link
Member

@philipag I haven't tested this, but there may be a workaround you can apply locally:

  1. Locate the file Xamarin.Shared.targets - it's probably something like C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\16.4.8968-net8-rc2\tools\msbuild\iOS\Xamarin.Shared.targets - and open it in a text editor.
  2. Find the _ExpandNativeReferences target (around line 140):
<Target Name="_ExpandNativeReferences" Condition="'$(DesignTimeBuild)' != 'true'" DependsOnTargets="_DetectSdkLocations;_ComputeTargetArchitectures;_GenerateBundleName">
	<ItemGroup>
		<_XCFrameworkNativeReference Include="@(NativeReference -> '%(Identity)/.')" Condition="'%(Extension)' == '.xcframework'" />
		<_FrameworkNativeReference Include="@(NativeReference -> '%(Identity)/%(Filename)')" Condition="'%(Extension)' == '.framework'" />
		<_FileNativeReference Include="@(NativeReference)" Condition="'%(Extension)' != '.framework' And '%(Extension)' != '.xcframework'" />
	</ItemGroup>
	<ResolveNativeReferences
		SessionId="$(BuildSessionId)"
		Condition="'$(IsMacEnabled)' == 'true' And '$(IsBindingProject)' != 'true'"
		Architectures="$(TargetArchitectures)"
		FrameworksDirectory="$(_AppFrameworksRelativePath)"
		IntermediateOutputPath="$(DeviceSpecificIntermediateOutputPath)"
		NativeReferences="@(_XCFrameworkNativeReference);@(_FrameworkNativeReference)"
		References="@(ReferencePath)"
		SdkIsSimulator="$(_SdkIsSimulator)"
		TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)"
		>
		<Output TaskParameter="NativeFrameworks" ItemName="_ResolvedNativeReference" />
	</ResolveNativeReferences>

	<ItemGroup>
		<_FrameworkNativeReference Include="@(_ResolvedNativeReference)" Condition="'%(Kind)' == 'Framework'" />
		<_FileNativeReference Include="@(_ResolvedNativeReference)" Condition="'%(Kind)' == 'Static' Or '%(Kind)' == 'Dynamic'" />
	</ItemGroup>
</Target>
  1. Remove the SessionId="$(BuildSessionId)" line, so that it reads:
<Target Name="_ExpandNativeReferences" Condition="'$(DesignTimeBuild)' != 'true'" DependsOnTargets="_DetectSdkLocations;_ComputeTargetArchitectures;_GenerateBundleName">
	<ItemGroup>
		<_XCFrameworkNativeReference Include="@(NativeReference -> '%(Identity)/.')" Condition="'%(Extension)' == '.xcframework'" />
		<_FrameworkNativeReference Include="@(NativeReference -> '%(Identity)/%(Filename)')" Condition="'%(Extension)' == '.framework'" />
		<_FileNativeReference Include="@(NativeReference)" Condition="'%(Extension)' != '.framework' And '%(Extension)' != '.xcframework'" />
	</ItemGroup>
	<ResolveNativeReferences
		Condition="'$(IsMacEnabled)' == 'true' And '$(IsBindingProject)' != 'true'"
		Architectures="$(TargetArchitectures)"
		FrameworksDirectory="$(_AppFrameworksRelativePath)"
		IntermediateOutputPath="$(DeviceSpecificIntermediateOutputPath)"
		NativeReferences="@(_XCFrameworkNativeReference);@(_FrameworkNativeReference)"
		References="@(ReferencePath)"
		SdkIsSimulator="$(_SdkIsSimulator)"
		TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)"
		>
		<Output TaskParameter="NativeFrameworks" ItemName="_ResolvedNativeReference" />
	</ResolveNativeReferences>

	<ItemGroup>
		<_FrameworkNativeReference Include="@(_ResolvedNativeReference)" Condition="'%(Kind)' == 'Framework'" />
		<_FileNativeReference Include="@(_ResolvedNativeReference)" Condition="'%(Kind)' == 'Static' Or '%(Kind)' == 'Dynamic'" />
	</ItemGroup>
</Target>
  1. Try to build again.

@skha83
Copy link
Author

skha83 commented Oct 17, 2023

With this temporary fix I'm able to build my app targeting iOS again 👍 thx a lot

rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Oct 17, 2023
…n building remotely in the ResolveNativeReferences task. Fixes xamarin#19173.

Fixes xamarin#19173.

Backport of xamarin#19227.
vs-mobiletools-engineering-service2 pushed a commit to vs-mobiletools-engineering-service2/xamarin-macios that referenced this issue Oct 17, 2023
vs-mobiletools-engineering-service2 pushed a commit to vs-mobiletools-engineering-service2/xamarin-macios that referenced this issue Oct 17, 2023
dalexsoto pushed a commit that referenced this issue Oct 17, 2023
…y in the ResolveNativeReferences task. Fixes #19173. (#19227)

Fixes #19173.
dalexsoto pushed a commit that referenced this issue Oct 17, 2023
…n building remotely in the ResolveNativeReferences task. Fixes #19173. (#19230)

Fixes #19173.

Backport of #19227.
dalexsoto pushed a commit that referenced this issue Oct 17, 2023
…ac when building remotely in the ResolveNativeReferences task. Fixes #19173. (#19235)

Fixes #19173.


Backport of #19227

Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
dalexsoto pushed a commit that referenced this issue Oct 17, 2023
…n building remotely in the ResolveNativeReferences task. Fixes #19173. (#19234)

Fixes #19173.


Backport of #19227

Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
@OudomMunint
Copy link

Got this error when trying the temp fix unfortunately:
Error MSB4018 The "ResolveNativeReferences" task failed unexpectedly.

@psdiviso
Copy link

@rolfbjarne
Hello. When I try your fix it seems like it works but when I try to open the app on the phone after build is done it just opens quickly and then closes again.

@montrelln
Copy link

@rolfbjarne this happens because MobileAds.SharedInstance is null with in the AppDelegate.cs FinishedLaunching method. This work around only allows you to build locally, but when you connect to mac you receive a totally different error. Have anyone found a fix where you can actually build using remote device, while paired to a mac?

@rolfbjarne
Copy link
Member

@rolfbjarne this happens because MobileAds.SharedInstance is null with in the AppDelegate.cs FinishedLaunching method. This work around only allows you to build locally, but when you connect to mac you receive a totally different error. Have anyone found a fix where you can actually build using remote device, while paired to a mac?

This should be fixed once we release .NET 8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug If an issue is a bug or a pull request a bug fix regression The issue or pull request is a regression
Projects
None yet
6 participants