diff --git a/src/Cli/dotnet/Commands/Test/VSTest/TestCommand.cs b/src/Cli/dotnet/Commands/Test/VSTest/TestCommand.cs index a17cc0031e13..0011141287c6 100644 --- a/src/Cli/dotnet/Commands/Test/VSTest/TestCommand.cs +++ b/src/Cli/dotnet/Commands/Test/VSTest/TestCommand.cs @@ -46,7 +46,7 @@ public static int Run(ParseResult parseResult) // Fix for https://github.com/Microsoft/vstest/issues/1453 // Run dll/exe directly using the VSTestForwardingApp - if (ContainsBuiltTestSources(args)) + if (ContainsBuiltTestSources(parseResult)) { return ForwardToVSTestConsole(parseResult, args, settings, testSessionCorrelationId); } @@ -295,18 +295,14 @@ internal static int RunArtifactPostProcessingIfNeeded(string testSessionCorrelat } } - private static bool ContainsBuiltTestSources(string[] args) + private static bool ContainsBuiltTestSources(ParseResult parseResult) { - for (int i = 0; i < args.Length; i++) + for (int i = 0; i < parseResult.UnmatchedTokens.Count; i++) { - string arg = args[i]; - if (arg.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) || arg.EndsWith(".exe", StringComparison.OrdinalIgnoreCase)) + string arg = parseResult.UnmatchedTokens[i]; + if (!arg.StartsWith("-") && + (arg.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) || arg.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))) { - var previousArg = i > 0 ? args[i - 1] : null; - if (previousArg != null && CommonOptions.PropertiesOption.Aliases.Contains(previousArg)) - { - return false; - } return true; } } diff --git a/test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs b/test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs index 96b0e9edb73b..6c054f61ceed 100644 --- a/test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs +++ b/test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs @@ -836,6 +836,28 @@ public void PropertiesEndingWithDotDllShouldNotFail(string property) result.ExitCode.Should().Be(1); } + [Fact] + public void DistributedLoggerEndingWithDotDllShouldBePassedToMSBuild() + { + var testProjectDirectory = CopyAndRestoreVSTestDotNetCoreTestApp([]); + + CommandResult result = new DotnetTestCommand(Log, disableNewOutput: true) + .WithWorkingDirectory(testProjectDirectory) + .Execute(ConsoleLoggerOutputNormal.Concat(["-dl:my.dll"])); + + if (!TestContext.IsLocalized()) + { + // This ensures that this was passed to MSBuild and not vstest.console. + result.StdOut.Should().Contain("error MSB1021: Cannot create an instance of the logger my.dll."); + } + else + { + result.StdOut.Should().Contain("MSB1021"); + } + + result.ExitCode.Should().Be(1); + } + private string CopyAndRestoreVSTestDotNetCoreTestApp(object[] parameters, [CallerMemberName] string callingMethod = "") { // Copy VSTestCore project in output directory of project dotnet-vstest.Tests