Azure-devops-docs: $AGENT_HOMEDIRECTORY/scripts/select-xamarin-sdk.sh doesn't work

Created on 17 Oct 2018  路  6Comments  路  Source: MicrosoftDocs/azure-devops-docs

When I run "cat $AGENT_HOMEDIRECTORY/scripts/select-xamarin-sdk.sh" the output I see, copied below, shows the Xamarin SDK version is being used to symlink the versions of Xamarin.*.framework/Versions yet they don't share similar version numbers. Additionally, we're instructed to use underscores instead of dots/periods yet I don't see where a valid path is reconstructed from those underscores. On my Mac the paths referenced use actual dots/periods.

#!/bin/bash
if [ -z "$1" ]; then
echo "No Xamarin SDK specified."
exit 0
fi

XAMARIN_SDK=$1

echo "Set Xamarin SDK to ${XAMARIN_SDK}"
FOLDERS_LIST=(
'/Library/Frameworks/Mono.framework/Versions'
'/Library/Frameworks/Xamarin.iOS.framework/Versions'
'/Library/Frameworks/Xamarin.Android.framework/Versions'
'/Library/Frameworks/Xamarin.Mac.framework/Versions'
)

for FOLDER in "${FOLDERS_LIST[@]}"
do
echo "Set Current folder for ${FOLDER}"
sudo rm -f ${FOLDER}/Current
sudo ln -s ${FOLDER}/${XAMARIN_SDK} ${FOLDER}/Current
done

Below is how I'm manually setting the version of Xcode being used (I need iOS 12 SDK support) and the versions of Xamarin.iOS and Mono directly.

/bin/bash -c "sudo cat $AGENT_HOMEDIRECTORY/scripts/select-xamarin-sdk.sh"
/bin/bash -c "sudo xcode-select -s /Applications/Xcode_10.app/Contents/Developer"
xcodebuild -showsdks

/bin/bash -c "sudo rm -f '/Library/Frameworks/Mono.framework/Versions/Current'"
/bin/bash -c "sudo ln -s '/Library/Frameworks/Mono.framework/Versions/5.12.0' '/Library/Frameworks/Mono.framework/Versions/Current'"

/bin/bash -c "sudo rm -f '/Library/Frameworks/Xamarin.iOS.framework/Versions/Current'"
/bin/bash -c "sudo ln -s '/Library/Frameworks/Xamarin.iOS.framework/Versions/12.0.0.15' '/Library/Frameworks/Xamarin.iOS.framework/Versions/Current'"

When I do this I get further along however my build fails with error: "MTOUCH : error MT0091: This version of Xamarin.iOS requires the iOS 12.0 SDK (shipped with Xcode 10.0). Either upgrade Xcode to get the required header files or set the managed linker behaviour to Link Framework SDKs Only (to try to avoid the new APIs)." My current project does have "Link Framework SDKs Only" as the build behavior and the guidance from the error code tells me to change the version of Xcode I'm using, which I'm already doing.

What am I missing?

Pri3

Most helpful comment

Using mrooths script I updated to fix jmichas problem I was running into also.

echo "Setting Xcode version to 10 for Visual Studio for Mac"
sudo xcode-select -s /Applications/Xcode_10.1.app/Contents/Developer
sudo xcodebuild -showsdks

echo "Appending AppleSdkRoot to Settings.plist"
mkdir -p /Users/vsts/Library/Preferences/Xamarin
cd /Users/vsts/Library/Preferences/Xamarin

echo "AppleSdkRoot/Applications/Xcode_10.1.app" >> Settings.plist

sudo rm -f '/Library/Frameworks/Mono.framework/Versions/Current'
sudo ln -s '/Library/Frameworks/Mono.framework/Versions/5.16.0' '/Library/Frameworks/Mono.framework/Versions/Current'

rm -f '/Library/Frameworks/Xamarin.iOS.framework/Versions/Current'
ln -s '/Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.15' '/Library/Frameworks/Xamarin.iOS.framework/Versions/Current'

All 6 comments

The final step was to append the correct AppleSdkRoot key in Settings.plist. Thanks goes to Andrew Schwenker for pointing that out. The complete script I use to build is below.

echo "Setting Xcode version to 10 for Visual Studio for Mac"
sudo xcode-select -s /Applications/Xcode_10.app/Contents/Developer
sudo xcodebuild -showsdks

echo "Appending AppleSdkRoot to Settings.plist"
mkdir -p /Users/vsts/Library/Preferences/Xamarin
cd /Users/vsts/Library/Preferences/Xamarin

echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"><plist version=\"1.0\"><dict><key>AppleSdkRoot</key><string>/Applications/Xcode_10.app</string></dict></plist>" >> Settings.plist

sudo rm -f '/Library/Frameworks/Mono.framework/Versions/Current'
sudo ln -s '/Library/Frameworks/Mono.framework/Versions/5.12.0' '/Library/Frameworks/Mono.framework/Versions/Current'

rm -f '/Library/Frameworks/Xamarin.iOS.framework/Versions/Current'
ln -s '/Library/Frameworks/Xamarin.iOS.framework/Versions/12.0.0.15' '/Library/Frameworks/Xamarin.iOS.framework/Versions/Current'

@mrooths
So, am I to do your thing instead of doing this:

SDKVERSION=5_12_0

sudo $AGENT_HOMEDIRECTORY/scripts/select-xamarin-sdk.sh $SDKVERSION

MONOPREFIX=/Library/Frameworks/Mono.framework/Versions/$SDKVERSION
echo "##vso[task.setvariable variable=DYLD_FALLBACK_LIBRARY_PATH;]$MONOPREFIX/lib:/lib:/usr/lib:$DYLD_LIBRARY_FALLBACK_PATH"
echo "##vso[task.setvariable variable=PKG_CONFIG_PATH;]$MONOPREFIX/lib/pkgconfig:$MONOPREFIX/share/pkgconfig:$PKG_CONFIG_PATH"
echo "##vso[task.setvariable variable=PATH;]$MONOPREFIX/bin:$PATH"

I keep getting emails from Apple that state:
"SDK Version Issue - This app was built with the iOS 11.4 SDK. Starting March 2019, all iOS apps submitted to the App Store must be built with the iOS 12.1 SDK or later, included in Xcode 10.1 or later."

I'm hoping your code is the solution.

Using mrooths script I updated to fix jmichas problem I was running into also.

echo "Setting Xcode version to 10 for Visual Studio for Mac"
sudo xcode-select -s /Applications/Xcode_10.1.app/Contents/Developer
sudo xcodebuild -showsdks

echo "Appending AppleSdkRoot to Settings.plist"
mkdir -p /Users/vsts/Library/Preferences/Xamarin
cd /Users/vsts/Library/Preferences/Xamarin

echo "AppleSdkRoot/Applications/Xcode_10.1.app" >> Settings.plist

sudo rm -f '/Library/Frameworks/Mono.framework/Versions/Current'
sudo ln -s '/Library/Frameworks/Mono.framework/Versions/5.16.0' '/Library/Frameworks/Mono.framework/Versions/Current'

rm -f '/Library/Frameworks/Xamarin.iOS.framework/Versions/Current'
ln -s '/Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.15' '/Library/Frameworks/Xamarin.iOS.framework/Versions/Current'

@Dsanders1 can't make it work with your script. It fails because of the plist step. My working script:

  echo "Setting Xcode version to 10 for Visual Studio for Mac"
  sudo xcode-select -s /Applications/Xcode_10.2.1.app/Contents/Developer

  echo "Appending AppleSdkRoot to Settings.plist"
  mkdir -p /Users/vsts/Library/Preferences/Xamarin
  cd /Users/vsts/Library/Preferences/Xamarin

  echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"><plist version=\"1.0\"><dict><key>AppleSdkRoot</key><string>/Applications/Xcode_10.2.1.app</string></dict></plist>" >> Settings.plist

  sudo rm -f '/Library/Frameworks/Mono.framework/Versions/Current'
  sudo ln -s '/Library/Frameworks/Mono.framework/Versions/6.0.0' '/Library/Frameworks/Mono.framework/Versions/Current'

  rm -f '/Library/Frameworks/Xamarin.iOS.framework/Versions/Current'
  ln -s '/Library/Frameworks/Xamarin.iOS.framework/Versions/12.14.0.114' '/Library/Frameworks/Xamarin.iOS.framework/Versions/Current'

for the ones arriving here and cannot find a working solution here is my working solution:
this is using the most recent version of xcode, mono and xamarin ios.

.NET Core 3 is used here because for versions of mono above 6.0.0 its requires .NET Core versions above 2.0.2x

this are de steps i needed in my .yml file.

steps:

- task: UseDotNet@2
  inputs:
    packageType: 'sdk'
    version: '3.0.x'

- bash: |    
    echo "Setting Xcode version"
    sudo xcode-select -s /Applications/Xcode_11.2.app/Contents/Developer

    echo "Setting Mono version"
    sudo rm -f '/Library/Frameworks/Mono.framework/Versions/Current'
    sudo ln -s '/Library/Frameworks/Mono.framework/Versions/6.4.0' '/Library/Frameworks/Mono.framework/Versions/Current'

    echo "Setting Xamarin.iOS version"
    rm -f '/Library/Frameworks/Xamarin.iOS.framework/Versions/Current'
    ln -s '/Library/Frameworks/Xamarin.iOS.framework/Versions/13.4.0.2' '/Library/Frameworks/Xamarin.iOS.framework/Versions/Current'    


  displayName: 'Set environment tools version'

@jzeferino your workaround stopped working due to some file system permission "fixes".

The issue is with the rm and ln commands executed without sudo.

My suggested "fixed" workaround:

steps:

- task: UseDotNet@2
  inputs:
    packageType: 'sdk'
    version: '3.0.x'

- bash: |    
    echo "Setting Xcode version"
    sudo xcode-select -s /Applications/Xcode_11.2.app/Contents/Developer

    echo "Setting Mono version"
    sudo rm -f '/Library/Frameworks/Mono.framework/Versions/Current'
    rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
    sudo ln -s '/Library/Frameworks/Mono.framework/Versions/6.4.0' '/Library/Frameworks/Mono.framework/Versions/Current'
    rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi

    echo "Setting Xamarin.iOS version"
    sudo rm -f '/Library/Frameworks/Xamarin.iOS.framework/Versions/Current'
    rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi
    sudo ln -s '/Library/Frameworks/Xamarin.iOS.framework/Versions/13.4.0.2' '/Library/Frameworks/Xamarin.iOS.framework/Versions/Current'    
    rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi

  displayName: 'Set environment tools version'

I additionally added rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi lines to make the build fail if some command has issues.

Was this page helpful?
0 / 5 - 0 ratings