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

Msbuild does not use default xcode version on hosted macOS agent to build Xamarin.Mac app #8388

Closed
4or5trees opened this issue Feb 2, 2023 · 6 comments
Labels
needs-triage Have yet to determine what bucket this goes in.

Comments

@4or5trees
Copy link

Issue Description

I have an issue with msbuild on my Azure DevOps hosted macOS agents.

As described in this Azure DevOps announcement, the way to select the xcode version should be done by performing:

sudo xcode-select -s "/Applications/Xcode_14.0.1.app"

In my pipeline there is an old Xamarin.Mac app that needs to be built with Xcode 14.0.1, otherwise the build will fail.
The _CoreCompileInterfaceDefinitions of the msbuild output an ibtool call with arguments pointing to:

--sdk /Applications/Xcode_14.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk

I can validate that the Xcode default version is set properly by running the code below after xcode-select:

xcode-select -print-path
xcodebuild -version

I've also tried pointing the Xcode.app symlink to my desired Xcode version but this did not fix the issue.

sudo rm -rf /Applications/Xcode.app
ln -svf /Applications/Xcode_14.0.1.app /Applications/Xcode.app 

Steps to Reproduce

  • Create sample Xamarin.Mac application

  • Create and run build for hosted macOS-12 agent on Azure DevOps:

    • Set xcode version sudo xcode-select -s "/Applications/Xcode_14.0.1.app"
    • Call msbuild to build sample Xamarin.Mac

Expected Behavior

  • Build succeeds

  • Build logs show _CoreCompileInterfaceDefinitions uses selected Xcode version to build

Actual Behavior

  • Build fails

  • Build logs show _CoreCompileInterfaceDefinitions uses macOS-12 agent default Xcode version 14.2

Ask us questions

How can I force msbuild to use a specific Xcode version for building my Xamarin.Mac app?

On my local Mac I don't have this issue (msbuild honors the selected Xcode version)

@4or5trees 4or5trees added the needs-triage Have yet to determine what bucket this goes in. label Feb 2, 2023
@rainersigwald
Copy link
Member

@radical any chance you can point @4or5trees in a direction for this Mono msbuild question?

@radical
Copy link
Member

radical commented Feb 7, 2023

cc @mrward

@mrward
Copy link

mrward commented Feb 7, 2023

Not an expert on this so not sure if Xamarin.Mac supports finding Xcode from xcode-select.

In VS Mac, when you configure the Xcode path in Preferences it writes a plist file with the path to the Xcode.app, which is used when msbuild builds the project.

~/Library/Preferences/Xamarin/Settings.plist

Looking at the Xamarin.Mac source code it looks like another way to configure this is via an MD_APPLE_SDK_ROOT environment variable.

@rolfbjarne will know the best approach here.

@mrward
Copy link

mrward commented Feb 7, 2023

Just above the code I linked to, it seems to use xcode-select as the last thing it tries. So maybe there is a settings.plist file overriding the default behaviour?

https://github.com/xamarin/Xamarin.MacDev/blob/14d53612d4624459a7ae617141c45e940ada6df5/Xamarin.MacDev/AppleSdkSettings.cs#L121

@rolfbjarne
Copy link
Member

The order is:

  1. Check the MD_APPLE_SDK_ROOT environment variable.
  2. Check the ~/Library/Preferences/Xamarin/Settings.plist file.
  3. Check xcode-select --print-path
  4. Use /Applications/Xcode.app

So I'm guessing you have a ~/Library/Preferences/Xamarin/Settings.plist file. The fix should be to remove that file (so that the build uses step 3. above instead).

@4or5trees
Copy link
Author

Hi guys, sorry for the late reply.

Thank you very much for your detailed responses!

Strangely, though, I have not been able to fix the build with them.
Default xcode version is still always 14.2 in macOS-12 agents.
It might be due to how the agents are configured, since in most builds the Settings.plist file does not exist but sometimes it does.

I have tried a variety of different things, including suggestions from comments above:

  • Deleting ~/Library/Preferences/Xamarin/Settings.plist before or after setting xcode-select version
  • Setting the $MD_APPLE_SDK_ROOT variable to /Applications/Xcode_14.0.1.app (this variable appears to never be filled by default)
  • Replacing existing /Applications/Xcode.app symlink to point to /Applications/Xcode_14.0.1.app
  • (and other things, I have lost track a bit)

I believe there might be a combination of fixes that I have not yet tried that will fix the issue. In case I find it, I will comment it here.

Additionally, we have unblocked our builds by manually selecting the macOS version. So the issue is not so urgent to fix for us at the moment.

So I think it should be OK to close this issue with this comment.

Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage Have yet to determine what bucket this goes in.
Projects
None yet
Development

No branches or pull requests

5 participants