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

Cannot build iOS binding library from the command line on Windows with msbuild #27098

Open
skuskusku opened this issue Jan 13, 2025 · 8 comments
Labels
migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working

Comments

@skuskusku
Copy link

Description

I have an iOS binding library targetting .NET 8 and I cannot build it successfully from the Windows command line. I can successfully build this library using Visual Studio 2022 (after having successfully paired with my Mac) and I can build it successfully on the mac itself using dotnet build, but building from the windows command line using msbuild.exe fails. My binding library is a P/Invoke Wrapper around a .a file (a fat library). I am using Visual Studio 2022 17.12.3 on Windows and I can reproduce this behaviour with two different MACs, one running with XCode 15.4 and the other with XCode 16.0. I could also reproduce this problem with an iOS binding library for .NET 9.

I am building like so on the command line:

msbuild.exe myIOSBindProj.sln /p:ServerAddress=%MAC_HOST% /p:ServerUser=%MAC_USER% /p:Configuration=Debug "/p:Platform=Any CPU" /t:Rebuild /v:diag

This assumes the solution file to be myIOSBindProj.sln and the user and computer name for the Mac to be in environment variables MAC_USER and MAC_HOST.

If I do this, the build will fail and the error (output shown in red) will be:

C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk.net8.0_18.0\18.0.8316\tools\msbuild\iOS\Xamarin.Shared.targets(1867,3):
 error : Could not find Microsoft.iOS in /usr/local/share/dotnet/packs/Microsoft.iOS.Sdk.net8.0_18.0/18.0.8316/. [c:\ap
plic\xamarin_native17.12\wrapper.netmaui\MathFuncs.iOS\MathFuncs.iOS.csproj]
C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk.net8.0_18.0\18.0.8316\tools\msbuild\iOS\Xamarin.Shared.targets(1867,3):
 error :          [c:\applic\xamarin_native17.12\wrapper.netmaui\MathFuncs.iOS\MathFuncs.iOS.csproj]


What is different here between the build via msbuild.exe and Visual Studio itself?

dotnet workload list tells me this:

Installed Workload Id      Manifest Version       Installation Source
---------------------------------------------------------------------
android                    35.0.7/9.0.100         VS 17.12.35527.113
aspire                     8.2.2/8.0.100          VS 17.12.35527.113
ios                        18.1.9163/9.0.100      VS 17.12.35527.113
maccatalyst                18.1.9163/9.0.100      VS 17.12.35527.113
maui-windows               9.0.0/9.0.100          VS 17.12.35527.113

Any help appreciated,

--
Stefan

Steps to Reproduce

  1. Create an iOS binding library, add the .a file to it
  2. Open the project in VS 2022 and pair with your mac
  3. Build the project, this should succeed
  4. Now close VS and open a command prompt in the solution directory for the iOS binding library
  5. Do a nuget restore for your solution
  6. run sth. like this: msbuild.exe myIOSBindProj.sln /p:ServerAddress=%MAC_HOST% /p:ServerUser=%MAC_USER% /p:Configuration=Debug "/p:Platform=Any CPU" /t:Rebuild /v:diag
  7. The build fails with the error shown above

Link to public reproduction project repository

No response

Version with bug

Unknown/Other

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS

Did you find any workaround?

I have no workaround for this, because this should be working from an automated build and in the Xamarin days this worked when building a Xamarin iOS binding library via msbuild.

Relevant log output

@skuskusku skuskusku added the t/bug Something isn't working label Jan 13, 2025
@drasticactions
Copy link
Contributor

The MAUI UI team doesn't maintain this tooling, I believe that belongs in xamarin-macios.

I'm unsure if it is possible to build a .NET binding library with msbuild, I think you would need to use dotnet to do it. @rolfbjarne can you please help?

@skuskusku
Copy link
Author

Hello everyone,

I think I found a solution for my problem. I installed dotnet-sdk-8.0.404-osx-x64.pkg on both macs, then did a

sudo dotnet workload install maui --source https://api.nuget.org/v3/index.json

on both machines and all of a sudden, I can build using msbuild on the windows command line. That doesn't explain why interactive builds using visual studio after pairing with the mac worked without it (can someone explain please?), but it is sufficient for me to work. So I would be happy if someone explained these weird circumstances, otherwise please close this ticket.

Thank you everyone,

--
Stefan

@skuskusku
Copy link
Author

The MAUI UI team doesn't maintain this tooling, I believe that belongs in xamarin-macios.

I'm unsure if it is possible to build a .NET binding library with msbuild, I think you would need to use dotnet to do it. @rolfbjarne can you please help?

using dotnet build on windows doesn't work, because it does not create a paired connection to the Mac, at least I could not find a way to do so from windows.

@rolfbjarne
Copy link
Member

I'm unsure if it is possible to build a .NET binding library with msbuild, I think you would need to use dotnet to do it. @rolfbjarne can you please help?

Correct, dotnet build works, msbuild won't.

using dotnet build on windows doesn't work, because it does not create a paired connection to the Mac, at least I could not find a way to do so from windows.

Yes, dotnet build will connect to the Mac if you pass the following properties:

  • ServerAddress=%MAC_HOST%
  • ServerUser=%MAC_USER%

like this:

dotnet build /p:ServerAddress=%MAC_HOST% /p:ServerUser=%MAC_USER% ...

Note that the command-line build won't automatically install anything on Mac, the correct version of .NET + the iOS workload must already be installed. The easiest way to accomplish this is to connect to the Mac from VS first, and build once (any iOS project).

There's some more information here: https://learn.microsoft.com/en-us/dotnet/maui/ios/pair-to-mac?view=net-maui-9.0#build-ios-apps-from-the-windows-command-line

@Zhanglirong-Winnie Zhanglirong-Winnie added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert labels Jan 14, 2025
@Marnie-Majait
Copy link

Marnie-Majait commented Jan 14, 2025

This issue has been verified Visual Studio 17.13 Preview 2.1 (.NET8 & .NET9). Can repro this issue on iOS platform.

Image

@skuskusku
Copy link
Author

Yes, dotnet build will connect to the Mac if you pass the following properties:

* ServerAddress=%MAC_HOST%

* ServerUser=%MAC_USER%

like this:

dotnet build /p:ServerAddress=%MAC_HOST% /p:ServerUser=%MAC_USER% ...

This works like a charm, thank you so much for sharing this.

--
Stefan

@konoshchenko
Copy link

This issue has been verified Visual Studio 17.13 Preview 2.1 (.NET8 & .NET9). Can repro this issue on iOS platform.

Image

Have you found the solution? I have the same problem and already spent days to find the solution.

@drasticactions
Copy link
Contributor

This issue has been verified Visual Studio 17.13 Preview 2.1 (.NET8 & .NET9). Can repro this issue on iOS platform.
Image

Have you found the solution? I have the same problem and already spent days to find the solution.

As stated above, you need to use the dotnet tooling for .NET platforms. You can't use msbuild for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants