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

.NET MAUI project doesnt build on VS Code but does on VS4Mac #19596

Closed
Syed-RI opened this issue Dec 7, 2023 · 8 comments
Closed

.NET MAUI project doesnt build on VS Code but does on VS4Mac #19596

Syed-RI opened this issue Dec 7, 2023 · 8 comments

Comments

@Syed-RI
Copy link

Syed-RI commented Dec 7, 2023

We have a project dependency on this nuget package which targets .NET 8. Unfortunately, the project fails to build on both Rider and VS Code but builds fine on VS 4 Mac. If we remove the nuget reference then it builds on all three IDE's. Im trying to understand whats the root cause and how to get around it.

P.S. Im running it on a M1 Mac

Steps to Reproduce

  1. Ensure you have .NET 8 SDK and MAUI workload installed
  2. Extract the attached repo and open the solution in VS Code (please ensure you have .NET MAUI and C# Dev kit extension installed)
  3. Target iOS and run the project

Expected Behavior

Project should build and deploy fine

Actual Behavior

Project build fails to build with:

/usr/local/share/dotnet/packs/Microsoft.iOS.Sdk/17.0.8478/targets/Xamarin.Shared.Sdk.targets(1556,3): error : clang++ exited with code 1: [/Users/name/Documents/Repos/MauiAppDotNet8/MauiAppDotNet8/MauiAppDotNet8.csproj::TargetFramework=net8.0-ios]
/usr/local/share/dotnet/packs/Microsoft.iOS.Sdk/17.0.8478/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', '-lc++', '-lcompression', '-liconv', '-lmono-component-debugger', '-lmono-component-diagnostics_tracing', '-lmono-component-hot_reload', '-lmono-component-marshal-ilgen', '-lmonosgen-2.0', '-lsqlite3', '-lxamarin-dotnet-debug', '-lz' [/Users/name/Documents/Repos/MauiAppDotNet8/MauiAppDotNet8/MauiAppDotNet8.csproj::TargetFramework=net8.0-ios]
/usr/local/share/dotnet/packs/Microsoft.iOS.Sdk/17.0.8478/targets/Xamarin.Shared.Sdk.targets(1556,3): error : ld: building for 'iOS-simulator', but linking in object file (/Users/name/Library/Caches/XamarinBuildDownload/MLKCore-5.0.0/Frameworks/MLKitCommon.framework/MLKitCommon[arm64][3](MLKAnalyticsLogger.o)) built for 'iOS' [/Users/name/Documents/Repos/MauiAppDotNet8/MauiAppDotNet8/MauiAppDotNet8.csproj::TargetFramework=net8.0-ios]
/usr/local/share/dotnet/packs/Microsoft.iOS.Sdk/17.0.8478/targets/Xamarin.Shared.Sdk.targets(1556,3): error : clang: error: linker command failed with exit code 1 (use -v to see invocation) [/Users/name/Documents/Repos/MauiAppDotNet8/MauiAppDotNet8/MauiAppDotNet8.csproj::TargetFramework=net8.0-ios]

Environment

Version information
Visual Studio Community 2022 for Mac
Version 17.6.7 (build 417)
Installation UUID: 368eeda2-b847-40ff-9ccf-8306652690f5

Runtime
.NET 7.0.3 (64-bit)
Architecture: Arm64
Microsoft.macOS.Sdk 13.1.1007; git-rev-head:8afca776a0a96613dfb7200e0917bb57f9ed5583; git-branch:release/7.0.1xx-xcode14.2

Roslyn (Language Service)
4.6.0-3.23180.6+99e956e42697a6dd886d1e12478ea2b27cceacfa

NuGet
Version: 6.4.0.117

.NET SDK (Arm64)
SDK: /usr/local/share/dotnet/sdk/8.0.100/Sdks
SDK Versions:
	8.0.100
	8.0.100-preview.6.23330.14
	8.0.100-preview.5.23303.2
	7.0.403
MSBuild SDKs: /Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/Sdks

.NET Runtime (Arm64)
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
	8.0.0
	7.0.14

.NET Runtime (x64)
Runtime: /usr/local/share/dotnet/x64/dotnet
Runtime Versions:
	3.1.32
	3.1.31
	3.1.30

Xamarin.Profiler
Version: 1.8.0.49
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

Updater
Version: 11

Apple Developer Tools
Xcode: 15.0.1 22266
Build: 15A507

Xamarin Designer
Version: 17.6.3.9
Hash: 2648399ae8
Branch: remotes/origin/d17-6
Build date: 2023-11-10 12:19:46 UTC

Xamarin.Mac
Version: 9.3.0.23 Visual Studio Community
Hash: 9defd91b3
Branch: xcode14.3
Build date: 2023-10-23 16:14:59-0400

Xamarin.Android
Version: 13.2.2.0 (Visual Studio Community)
Commit: xamarin-android/d17-5/45b0e14
Android SDK: /Users/syedhoque/Library/Android/sdk
	Supported Android versions:
		12.1 (API level 32)
		12.0 (API level 31)
		11.0 (API level 30)
		9.0  (API level 28)
		13.0 (API level 33)

SDK Command-line Tools Version: 7.0
SDK Platform Tools Version: 34.0.1
SDK Build Tools Version: 34.0.0 rc3

Build Information: 
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

Microsoft Build of OpenJDK
Java SDK: /Library/Java/JavaVirtualMachines/microsoft-11.jdk
11.0.16.1
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Eclipse Temurin JDK
Java SDK: /Library/Java/JavaVirtualMachines/temurin-8.jdk
1.8.0.302
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Android SDK Manager
Version: 17.6.0.50
Hash: a715dca
Branch: HEAD
Build date: 2023-11-10 12:19:52 UTC

Android Device Manager
Version: 0.0.0.1309
Hash: 06e3e77
Branch: HEAD
Build date: 2023-11-10 12:19:52 UTC

Xamarin.iOS
Version: 16.4.0.23 Visual Studio Community
Hash: 9defd91b3
Branch: xcode14.3
Build date: 2023-10-23 16:15:00-0400

Build Information
Release ID: 1706070417
Git revision: 179aa48a5702754e41a8218d0403ddc3be46706f
Build date: 2023-11-10 12:18:09+00
Build branch: release-17.6
Build lane: release-17.6

Operating System
Mac OS X 14.1.2
Darwin 23.1.0 Darwin Kernel Version 23.1.0
    Mon Oct  9 21:27:24 PDT 2023
    root:xnu-10002.41.9~6/RELEASE_ARM64_T6000 arm64

Enabled user installed extensions
.NET Core Extensions 0.7
NuGet Package Explorer 0.12
CSharp Interactive 0.5
NuGet Package Management Extensions 0.34
VisualStudio View Inspector 0.9.1

Build Logs

VSCodeLog.txt
RiderLog.txt

Example Project (If Possible)

MauiAppDotNet8.zip

@rolfbjarne
Copy link
Member

The problem is that the NuGet doesn't support the arm64 architecture in the simulator.

This is explained a bit more in the release notes for .NET 8: https://github.com/xamarin/xamarin-macios/wiki/.NET-8-release-notes#default-runtimeidentifiers

Looks like there's also an issue filed: JimmyPun610/BarcodeScanner.Mobile#211

@Syed-RI
Copy link
Author

Syed-RI commented Dec 7, 2023

The problem is that the NuGet doesn't support the arm64 architecture in the simulator.

This is explained a bit more in the release notes for .NET 8: https://github.com/xamarin/xamarin-macios/wiki/.NET-8-release-notes#default-runtimeidentifiers

Looks like there's also an issue filed: JimmyPun610/BarcodeScanner.Mobile#211

Thanks @rolfbjarne , but whats the workaround for me in this case? I have team members who are on intel macs and Im on M1 macs. How do we go about implementing a workaround that caters for both? Can you please help me out pointing to correct properties?

@rolfbjarne
Copy link
Member

The problem is that the NuGet doesn't support the arm64 architecture in the simulator.
This is explained a bit more in the release notes for .NET 8: Wiki: .NET 8 release notes (default runtimeidentifiers) ()
Looks like there's also an issue filed: JimmyPun610/BarcodeScanner.Mobile#211

Thanks @rolfbjarne , but whats the workaround for me in this case? I have team members who are on intel macs and Im on M1 macs. How do we go about implementing a workaround that caters for both? Can you please help me out pointing to correct properties?

It's not very pretty, but if you add this to the csproj:

<PropertyGroup>
    <RuntimeIdentifier>iossimulator-x64</RuntimeIdentifier>
</PropertyGroup>

that will work on both x64 and arm64 macs.

However, if you want to build for device, you'll have to remove it (when building for device the correct RuntimeIdentifier is ios-arm64).

You might be able to do something like this if you can select the current configuration in your IDE of choice - you create two configurations, named iPhoneSimulator and iPhone, and switch between them to select how to build (the names of the configurations don't matter, you can choose whatever you want).

<PropertyGroup>
    <RuntimeIdentifier Condition="'$(Configuration)' == 'iPhoneSimulator'">iossimulator-x64</RuntimeIdentifier>
    <RuntimeIdentifier Condition="'$(Configuration)' == 'iPhone'">ios-arm64</RuntimeIdentifier>
</PropertyGroup>

@Syed-RI
Copy link
Author

Syed-RI commented Dec 7, 2023

Ive dumped this in the csproj to test

<PropertyGroup Condition="'$(TargetFramework)' == 'net8.0-ios'">
        <RuntimeIdentifier>iossimulator-x64</RuntimeIdentifier>
 </PropertyGroup>

Builds fine but not deploying yo simulator:
Screenshot 2023-12-07 at 17 34 23

Thats in Rider, but VS code fails to build just as before :(

@rolfbjarne
Copy link
Member

I can't speak for Rider, but for VSCode, would it be possible to get a binlog (https://aka.ms/binlog)?

@Syed-RI
Copy link
Author

Syed-RI commented Dec 8, 2023

That link doesnt explain how to capture it from VS Code. However, I noticed this in the output:

The terminal process "/bin/zsh '-l', '-c', 'dotnet build -t:Build -p:Configuration=Debug -f net8.0-ios -r iossimulator-arm64 -p:CustomAfterMicrosoftCSharpTargets="/Users/syedhoque/.vscode/extensions/ms-dotnettools.dotnet-maui-0.5.50-darwin-arm64/dist/resources/Custom.After.Microsoft.CSharp.targets" -p:MauiVSCodeBuildOutputFile=/var/folders/lq/_klkbqnj66z16sf49wm_5t7h0000gn/T/dotnet-maui/maui-vsc-996e1a9e-348f-41ad-9014-9ca962e01c18.json -v:normal -bl /Users/syedhoque/Documents/Repos/MauiAppDotNet8/MauiAppDotNet8/MauiAppDotNet8.csproj'" terminated with exit code: 1. 

Note that -r iossimulator-arm64 flag, basically thats overriding the csproj when I hit build and debug. If I run dotnet build -t:Build -p:Configuration=Debug -f net8.0-ios -bl from terminal the build succeeds but that means I cant debug. Is someone able to dig out from VS 4 Mac to see what flags its passing in to build and debug correctly that VS Code cant? Feeling desperate here.

@edgedj
Copy link

edgedj commented Dec 8, 2023

link to a duplicate of this issue: microsoft/vscode-dotnettools#744

@rolfbjarne
Copy link
Member

This is an issue in VSCode, so let's track this in microsoft/vscode-dotnettools#744.

@xamarin xamarin locked as resolved and limited conversation to collaborators Dec 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants