-
-
Save abock/ebf88068ea85c1d97fb69f8e5552351c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ReloadXcodeSettings.cs | |
// | |
// Author: | |
// Aaron Bockover <abock@xamarin.com> | |
// | |
// Copyright 2017 Microsoft. All rights reserved. | |
using System; | |
using System.Reflection; | |
using Microsoft.Build.Utilities; | |
namespace Xamarin.MSBuild | |
{ | |
public sealed class ReloadXcodeSettings : Task | |
{ | |
public string XcodePath { get; set; } | |
public override bool Execute () | |
{ | |
var assembly = Assembly.Load ("Xamarin.MacDev"); | |
if (assembly == null) { | |
Log.LogError ("Xamarin.MacDev.dll is not loaded in the app domain"); | |
return false; | |
} | |
var settingsType = assembly.GetType ("Xamarin.MacDev.AppleSdkSettings"); | |
if (settingsType == null) { | |
Log.LogError ($"Cannot load Xamarin.MacDev.AppleSdkSettings from {assembly}"); | |
return false; | |
} | |
var initMethod = settingsType.GetMethod ( | |
"Init", | |
BindingFlags.NonPublic | BindingFlags.Static); | |
if (initMethod == null) { | |
Log.LogError ($"Cannot load {settingsType.FullName}.Init() from {assembly}"); | |
return false; | |
} | |
if (XcodePath == null) | |
Log.LogMessage ($"Unsetting MD_APPLE_SDK_ROOT"); | |
else | |
Log.LogMessage ($"Setting MD_APPLE_SDK_ROOT to {XcodePath}"); | |
Environment.SetEnvironmentVariable ("MD_APPLE_SDK_ROOT", XcodePath); | |
Log.LogMessage ($"Invoking {initMethod.DeclaringType.FullName}.{initMethod.Name}"); | |
initMethod.Invoke (null, null); | |
return true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment