Skip to content

Instantly share code, notes, and snippets.

@abock
Created September 26, 2017 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abock/ebf88068ea85c1d97fb69f8e5552351c to your computer and use it in GitHub Desktop.
Save abock/ebf88068ea85c1d97fb69f8e5552351c to your computer and use it in GitHub Desktop.
//
// 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