From 018c9a49274b7072095667df5ea1e02ebf7242f9 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 16 Oct 2025 09:21:42 +0200 Subject: [PATCH] [msbuild] Show an error if SdkDevPath hasn't been set and we're executing a process. --- msbuild/Xamarin.Localization.MSBuild/MSBStrings.resx | 4 ++++ msbuild/Xamarin.MacDev.Tasks/Tasks/XamarinTask.cs | 10 ++++++++-- .../Xamarin.MacDev.Tasks.Tests/TestHelpers/TestBase.cs | 2 ++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/msbuild/Xamarin.Localization.MSBuild/MSBStrings.resx b/msbuild/Xamarin.Localization.MSBuild/MSBStrings.resx index 73f4ff1ab063..f85052143906 100644 --- a/msbuild/Xamarin.Localization.MSBuild/MSBStrings.resx +++ b/msbuild/Xamarin.Localization.MSBuild/MSBStrings.resx @@ -1620,6 +1620,10 @@ Unable to copy the inputs to this task to the remote build server for unknown reasons. The build log may have more information. + + The task '{0}' is trying to call an external process, but a path to Xcode has not been provided. Please file an issue at https://github.com/dotnet/macios/issues/new/choose. + + The task '{0}' requires the property '{1}' to be set. Please file an issue at https://github.com/dotnet/macios/issues/new/choose. diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/XamarinTask.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/XamarinTask.cs index d52727b1a4be..2b5aaf579a50 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/XamarinTask.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/XamarinTask.cs @@ -111,17 +111,23 @@ protected string GetSdkPlatform (bool isSimulator) internal protected System.Threading.Tasks.Task ExecuteAsync (string fileName, IList arguments, Dictionary? environment = null, bool showErrorIfFailure = true, string? workingDirectory = null, CancellationToken? cancellationToken = null) { - return ExecuteAsync (Log, fileName, arguments, SdkDevPath, environment, showErrorIfFailure, workingDirectory, cancellationToken); + return ExecuteAsync (this, fileName, arguments, SdkDevPath, environment, showErrorIfFailure, workingDirectory, cancellationToken); } static int executionCounter; - static async System.Threading.Tasks.Task ExecuteAsync (TaskLoggingHelper log, string fileName, IList arguments, string? sdkDevPath = null, Dictionary? environment = null, bool showErrorIfFailure = true, string? workingDirectory = null, CancellationToken? cancellationToken = null) + static async System.Threading.Tasks.Task ExecuteAsync (Task task, string fileName, IList arguments, string? sdkDevPath = null, Dictionary? environment = null, bool showErrorIfFailure = true, string? workingDirectory = null, CancellationToken? cancellationToken = null) { + var log = task.Log; // Create a new dictionary if we're given one, to make sure we don't change the caller's dictionary. var launchEnvironment = environment is null ? new Dictionary () : new Dictionary (environment); if (!string.IsNullOrEmpty (sdkDevPath)) launchEnvironment ["DEVELOPER_DIR"] = sdkDevPath; + if (Environment.OSVersion.Platform == PlatformID.MacOSX && string.IsNullOrEmpty (sdkDevPath)) { + log.LogError (MSBStrings.E7164 /* The task '{0}' is trying to call an external process, but a path to Xcode has not been provided. Please file an issue at https://github.com/dotnet/macios/issues/new/choose. */, task.GetType ().Name); + log.LogMessage (MessageImportance.Low, Environment.StackTrace); + } + var currentId = Interlocked.Increment (ref executionCounter); log.LogMessage (MessageImportance.Normal, MSBStrings.M0001, currentId, fileName, StringUtils.FormatArguments (arguments)); // Started external tool execution #{0}: {1} {2} if (!string.IsNullOrEmpty (workingDirectory)) { diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TestHelpers/TestBase.cs b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TestHelpers/TestBase.cs index 8f38b34b0225..3856dc0dc097 100644 --- a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TestHelpers/TestBase.cs +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TestHelpers/TestBase.cs @@ -53,6 +53,8 @@ public virtual void Setup () { var t = new T (); t.BuildEngine = Engine; + if (t is XamarinTask xt) + xt.SdkDevPath = Configuration.xcode_root; return t; }