diff --git a/msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.ObjCBinding.CSharp.targets b/msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.ObjCBinding.CSharp.targets index ef31d5bda8..f339d83d53 100644 --- a/msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.ObjCBinding.CSharp.targets +++ b/msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.ObjCBinding.CSharp.targets @@ -74,12 +74,14 @@ Copyright (C) 2014 Xamarin Inc. All rights reserved. CoreSources="@(ObjcBindingCoreSource)" DefineConstants="$(DefineConstants)" EmitDebugInformation="$(BTouchEmitDebugInformation)" + ExtraArgs="$(BTouchExtraArgs)" GeneratedSourcesDir="$(GeneratedSourcesDir)" GeneratedSourcesFileList="$(_GeneratedSourcesFileList)" Namespace="$(Namespace)" NoStdLib="$(NoStdLib)" OutputAssembly="$(OutputAssembly)" ProcessEnums="$(ProcessEnums)" + ProjectDir="$(MSBuildProjectDirectory)" References="@(ReferencePath);@(BTouchReferencePath)" TargetFrameworkIdentifier="$(TargetFrameworkIdentifier)" FrameworkRoot="$(XamarinMacFrameworkRoot)" diff --git a/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/BTouchTaskBase.cs b/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/BTouchTaskBase.cs index 8d80082200..ef143d8fab 100644 --- a/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/BTouchTaskBase.cs +++ b/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/BTouchTaskBase.cs @@ -42,6 +42,8 @@ namespace Xamarin.MacDev.Tasks { public bool EmitDebugInformation { get; set; } + public string ExtraArgs { get; set; } + public string GeneratedSourcesDir { get; set; } public string GeneratedSourcesFileList { get; set; } @@ -54,6 +56,9 @@ namespace Xamarin.MacDev.Tasks { public bool ProcessEnums { get; set; } + [Required] + public string ProjectDir { get; set; } + public ITaskItem[] References { get; set; } public ITaskItem[] Resources { get; set; } @@ -83,9 +88,11 @@ namespace Xamarin.MacDev.Tasks { protected override string GenerateCommandLineCommands () { var cmd = new CommandLineBuilder (); + #if DEBUG cmd.AppendSwitch ("/v"); #endif + if (NoStdLib) cmd.AppendSwitch ("/nostdlib"); cmd.AppendSwitchIfNotNull ("/compiler:", CompilerPath); @@ -98,6 +105,7 @@ namespace Xamarin.MacDev.Tasks { dir = Path.GetDirectoryName (BaseLibDll); else dir = null; + cmd.AppendSwitchIfNotNull ("/lib:", dir); cmd.AppendSwitchIfNotNull ("/r:", Path.Combine (dir, "mscorlib.dll")); } @@ -185,6 +193,38 @@ namespace Xamarin.MacDev.Tasks { cmd.AppendSwitch (GetTargetFrameworkArgument ()); + if (!string.IsNullOrEmpty (ExtraArgs)) { + var extraArgs = ProcessArgumentBuilder.Parse (ExtraArgs); + var target = OutputAssembly; + string projectDir; + + if (ProjectDir.StartsWith ("~/", StringComparison.Ordinal)) { + // Note: Since the Visual Studio plugin doesn't know the user's home directory on the Mac build host, + // it simply uses paths relative to "~/". Expand these paths to their full path equivalents. + var home = Environment.GetFolderPath (Environment.SpecialFolder.UserProfile); + + projectDir = Path.Combine (home, ProjectDir.Substring (2)); + } else { + projectDir = ProjectDir; + } + + var customTags = new Dictionary (StringComparer.OrdinalIgnoreCase) { + { "projectdir", projectDir }, + // Apparently msbuild doesn't propagate the solution path, so we can't get it. + // { "solutiondir", proj.ParentSolution != null ? proj.ParentSolution.BaseDirectory : proj.BaseDirectory }, + { "targetpath", Path.Combine (Path.GetDirectoryName (target), Path.GetFileName (target)) }, + { "targetdir", Path.GetDirectoryName (target) }, + { "targetname", Path.GetFileName (target) }, + { "targetext", Path.GetExtension (target) }, + }; + + for (int i = 0; i < extraArgs.Length; i++) { + var argument = extraArgs[i]; + + cmd.AppendTextUnquoted (StringParserService.Parse (argument, customTags)); + } + } + return cmd.ToString (); } @@ -224,6 +264,7 @@ namespace Xamarin.MacDev.Tasks { Log.LogTaskProperty ("CoreSources", CoreSources); Log.LogTaskProperty ("DefineConstants", DefineConstants); Log.LogTaskProperty ("EmitDebugInformation", EmitDebugInformation); + Log.LogTaskProperty ("ExtraArgs", ExtraArgs); Log.LogTaskProperty ("GeneratedSourcesDir", GeneratedSourcesDir); Log.LogTaskProperty ("GeneratedSourcesFileList", GeneratedSourcesFileList); Log.LogTaskProperty ("Namespace", Namespace); @@ -231,6 +272,7 @@ namespace Xamarin.MacDev.Tasks { Log.LogTaskProperty ("NoStdLib", NoStdLib); Log.LogTaskProperty ("OutputAssembly", OutputAssembly); Log.LogTaskProperty ("ProcessEnums", ProcessEnums); + Log.LogTaskProperty ("ProjectDir", ProjectDir); Log.LogTaskProperty ("References", References); Log.LogTaskProperty ("Resources", Resources); Log.LogTaskProperty ("Sources", Sources); diff --git a/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.ObjCBinding.CSharp.targets b/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.ObjCBinding.CSharp.targets index 7aa35b4b22..7a7aeeec28 100644 --- a/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.ObjCBinding.CSharp.targets +++ b/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.ObjCBinding.CSharp.targets @@ -68,13 +68,15 @@ Copyright (C) 2013-2016 Xamarin Inc. All rights reserved. CompilerPath="$(CscPath)" CoreSources="@(ObjcBindingCoreSource)" DefineConstants="$(DefineConstants)" - EmitDebugInformation="$(BTouchEmitDebugInformation)" + EmitDebugInformation="$(BTouchEmitDebugInformation)" + ExtraArgs="$(BTouchExtraArgs)" GeneratedSourcesDir="$(GeneratedSourcesDir)" GeneratedSourcesFileList="$(_GeneratedSourcesFileList)" Namespace="$(Namespace)" NoStdLib="$(NoStdLib)" OutputAssembly="$(OutputAssembly)" ProcessEnums="$(ProcessEnums)" + ProjectDir="$(MSBuildProjectDirectory)" References="@(ReferencePath);@(BTouchReferencePath)" TargetFrameworkIdentifier="$(TargetFrameworkIdentifier)" BTouchToolPath="$(BTouchToolPath)"