diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/AOTCompileTaskBase.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/AOTCompileTaskBase.cs index c32ed8ebaca8..f07d9013b871 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/AOTCompileTaskBase.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/AOTCompileTaskBase.cs @@ -176,13 +176,13 @@ public override bool Execute () Directory.CreateDirectory (OutputDirectory); var aotAssemblyFiles = new List (); - var processes = new Task [assembliesToAOT.Length]; var environment = new Dictionary { { "MONO_PATH", Path.GetFullPath (InputDirectory) }, }; var globalAotArguments = AotArguments?.Select (v => v.ItemSpec).ToList (); + var listOfArguments = new List<(IList Arguments, string Input)> (); for (var i = 0; i < assembliesToAOT.Length; i++) { var asm = assembliesToAOT [i]; var input = asm.GetMetadata ("Input"); @@ -212,16 +212,20 @@ public override bool Execute () arguments.AddRange (parsedProcessArguments); arguments.Add (input); - processes [i] = ExecuteAsync (AOTCompilerPath, arguments, environment: environment, sdkDevPath: SdkDevPath, showErrorIfFailure: false /* we show our own error below */) + listOfArguments.Add (new (arguments, input)); + } + + Parallel.ForEach (listOfArguments, (arg) => { + ExecuteAsync (AOTCompilerPath, arg.Arguments, environment: environment, sdkDevPath: SdkDevPath, showErrorIfFailure: false /* we show our own error below */) .ContinueWith ((v) => { if (v.Result.ExitCode != 0) - Log.LogError (MSBStrings.E7118 /* Failed to AOT compile {0}, the AOT compiler exited with code {1} */, Path.GetFileName (input), v.Result.ExitCode); + Log.LogError (MSBStrings.E7118 /* Failed to AOT compile {0}, the AOT compiler exited with code {1} */, Path.GetFileName (arg.Input), v.Result.ExitCode); return System.Threading.Tasks.Task.FromResult (v.Result); - }).Unwrap (); - } - - System.Threading.Tasks.Task.WaitAll (processes); + }) + .Unwrap () + .Wait (); + }); AssemblyFiles = aotAssemblyFiles.ToArray ();