From 16eca88e2e5b35cfbc38ad8a708eab4bae1e9b2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Fri, 19 Sep 2025 14:48:37 +0200 Subject: [PATCH] Property with .dll should not offload test run to vstest.console.exe --- .../Commands/Test/VSTest/TestCommand.cs | 11 +++++-- ...enDotnetTestBuildsAndRunsTestfromCsproj.cs | 32 +++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/Cli/dotnet/Commands/Test/VSTest/TestCommand.cs b/src/Cli/dotnet/Commands/Test/VSTest/TestCommand.cs index cf082e5e052e..51df89df08e0 100644 --- a/src/Cli/dotnet/Commands/Test/VSTest/TestCommand.cs +++ b/src/Cli/dotnet/Commands/Test/VSTest/TestCommand.cs @@ -298,11 +298,16 @@ internal static int RunArtifactPostProcessingIfNeeded(string testSessionCorrelat private static bool ContainsBuiltTestSources(string[] args) { - foreach (string arg in args) + for (int i = 0; i < args.Length; i++) { - if (!arg.StartsWith("-") && - (arg.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) || arg.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))) + string arg = args[i]; + if (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 85d6749e07a5..96b0e9edb73b 100644 --- a/test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs +++ b/test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs @@ -804,6 +804,38 @@ public void ArgumentsEndWithDllOrExeShouldNotFail(string arg) } } + + [Theory] + [InlineData("-p:ABC=C:\\my.dll")] + [InlineData("/p:ABC=C:\\my.dll")] + [InlineData("-property:ABC=C:\\my.dll")] + public void PropertiesEndingWithDotDllShouldNotFail(string property) + { + var testProjectDirectory = CopyAndRestoreVSTestDotNetCoreTestApp([]); + + // Call test + // The test will complain about --property:VsTestUseMSBuildOutput=false but + // it is the .dll parameter that is causing this. It forces the command to offload work + // to vstest.console.exe directly, because it thinks there is some test .dll that we should run + // directly, rather than a project file. + // Vstest.console.exe will then complain just about the first unknown parameter. + CommandResult result = new DotnetTestCommand(Log, disableNewOutput: true) + .WithWorkingDirectory(testProjectDirectory) + .Execute(ConsoleLoggerOutputNormal.Concat([property])); + + // Verify + if (!TestContext.IsLocalized()) + { + result.StdOut.Should().Contain("Total tests: 2"); + result.StdOut.Should().Contain("Passed: 1"); + result.StdOut.Should().Contain("Failed: 1"); + result.StdOut.Should().Contain("Passed VSTestPassTest"); + result.StdOut.Should().Contain("Failed VSTestFailTest"); + } + + result.ExitCode.Should().Be(1); + } + private string CopyAndRestoreVSTestDotNetCoreTestApp(object[] parameters, [CallerMemberName] string callingMethod = "") { // Copy VSTestCore project in output directory of project dotnet-vstest.Tests