From c813c0e6815e9693875a3ae6f2f6561e0300a3e6 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Thu, 30 Jan 2025 13:29:41 +0100 Subject: [PATCH] Fix InvokeTestingPlatformTask to handle running with msbuild.exe and 'Test' target --- .../Tasks/InvokeTestingPlatformTask.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Platform/Microsoft.Testing.Platform.MSBuild/Tasks/InvokeTestingPlatformTask.cs b/src/Platform/Microsoft.Testing.Platform.MSBuild/Tasks/InvokeTestingPlatformTask.cs index f62a9d809e..c7677a33e1 100644 --- a/src/Platform/Microsoft.Testing.Platform.MSBuild/Tasks/InvokeTestingPlatformTask.cs +++ b/src/Platform/Microsoft.Testing.Platform.MSBuild/Tasks/InvokeTestingPlatformTask.cs @@ -23,7 +23,7 @@ namespace Microsoft.Testing.Platform.MSBuild; public class InvokeTestingPlatformTask : Build.Utilities.ToolTask, IDisposable { private const string MonoRunnerName = "mono"; - private const string DotnetRunnerName = "dotnet"; + private static readonly string DotnetRunnerName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "dotnet.exe" : "dotnet"; private readonly IFileSystem _fileSystem; private readonly PipeNameDescription _pipeNameDescription; @@ -90,7 +90,7 @@ protected override string ToolName if (TargetPath.ItemSpec.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase)) { Log.LogMessage(MessageImportance.Low, $"Target path is a dll '{TargetPath.ItemSpec}'"); - return DotnetRunnerName + (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : string.Empty); + return DotnetRunnerName; } // If the target is an exe and we're not on Windows we try with the mono runner. @@ -182,8 +182,7 @@ protected override string GenerateCommandLineCommands() if (IsNetCoreApp) { - string dotnetRunnerName = ToolName; - if (dotnetRunnerName != MonoRunnerName && Path.GetFileName(_currentProcess.MainModule!.FileName!).Equals(dotnetRunnerName, StringComparison.OrdinalIgnoreCase)) + if (ToolName == DotnetRunnerName) { builder.AppendSwitch("exec"); builder.AppendFileNameIfNotNull(TargetPath.ItemSpec);