Skip to content

Commit 7df4cd9

Browse files
Copilotbaronfel
andcommitted
Fix tests to explicitly use ConsoleLogger to prevent CI/CD logger auto-detection
Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
1 parent 7847339 commit 7df4cd9

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

src/MSBuild.UnitTests/MSBuildServer_Tests.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void MSBuildServerTest()
9999
int pidOfServerProcess = ParseNumber(output, "Server ID is ");
100100
pidOfInitialProcess.ShouldNotBe(pidOfServerProcess, "We started a server node to execute the target rather than running it in-proc, so its pid should be different.");
101101

102-
output = RunnerUtilities.ExecMSBuild(BuildEnvironmentHelper.Instance.CurrentMSBuildExePath, project.Path, out success, false, _output);
102+
output = ExecMSBuildWithConsoleLogger(project.Path, out success);
103103
success.ShouldBeTrue();
104104
int newPidOfInitialProcess = ParseNumber(output, "Process ID is ");
105105
newPidOfInitialProcess.ShouldNotBe(pidOfServerProcess, "We started a server node to execute the target rather than running it in-proc, so its pid should be different.");
@@ -125,7 +125,7 @@ public void MSBuildServerTest()
125125
RunnerUtilities.ExecMSBuild(BuildEnvironmentHelper.Instance.CurrentMSBuildExePath, sleepProject.Path, out _);
126126

127127
// Ensure that a new build can still succeed and that its server node is different.
128-
output = RunnerUtilities.ExecMSBuild(BuildEnvironmentHelper.Instance.CurrentMSBuildExePath, project.Path, out success, false, _output);
128+
output = ExecMSBuildWithConsoleLogger(project.Path, out success);
129129

130130
success.ShouldBeTrue();
131131
newPidOfInitialProcess = ParseNumber(output, "Process ID is ");
@@ -152,14 +152,14 @@ public void VerifyMixedLegacyBehavior()
152152
pidOfInitialProcess.ShouldNotBe(pidOfServerProcess, "We started a server node to execute the target rather than running it in-proc, so its pid should be different.");
153153

154154
Environment.SetEnvironmentVariable("MSBUILDUSESERVER", "");
155-
output = RunnerUtilities.ExecMSBuild(BuildEnvironmentHelper.Instance.CurrentMSBuildExePath, project.Path, out success, false, _output);
155+
output = ExecMSBuildWithConsoleLogger(project.Path, out success);
156156
success.ShouldBeTrue();
157157
pidOfInitialProcess = ParseNumber(output, "Process ID is ");
158158
int pidOfNewserverProcess = ParseNumber(output, "Server ID is ");
159159
pidOfInitialProcess.ShouldBe(pidOfNewserverProcess, "We did not start a server node to execute the target, so its pid should be the same.");
160160

161161
Environment.SetEnvironmentVariable("MSBUILDUSESERVER", "1");
162-
output = RunnerUtilities.ExecMSBuild(BuildEnvironmentHelper.Instance.CurrentMSBuildExePath, project.Path, out success, false, _output);
162+
output = ExecMSBuildWithConsoleLogger(project.Path, out success);
163163
success.ShouldBeTrue();
164164
pidOfInitialProcess = ParseNumber(output, "Process ID is ");
165165
pidOfNewserverProcess = ParseNumber(output, "Server ID is ");
@@ -211,13 +211,13 @@ public void BuildsWhileBuildIsRunningOnServer()
211211

212212
Environment.SetEnvironmentVariable("MSBUILDUSESERVER", "0");
213213

214-
output = RunnerUtilities.ExecMSBuild(BuildEnvironmentHelper.Instance.CurrentMSBuildExePath, project.Path, out success, false, _output);
214+
output = ExecMSBuildWithConsoleLogger(project.Path, out success);
215215
success.ShouldBeTrue();
216216
ParseNumber(output, "Server ID is ").ShouldBe(ParseNumber(output, "Process ID is "), "There should not be a server node for this build.");
217217

218218
Environment.SetEnvironmentVariable("MSBUILDUSESERVER", "1");
219219

220-
output = RunnerUtilities.ExecMSBuild(BuildEnvironmentHelper.Instance.CurrentMSBuildExePath, project.Path, out success, false, _output);
220+
output = ExecMSBuildWithConsoleLogger(project.Path, out success);
221221
success.ShouldBeTrue();
222222
pidOfServerProcess.ShouldNotBe(ParseNumber(output, "Server ID is "), "The server should be otherwise occupied.");
223223
pidOfServerProcess.ShouldNotBe(ParseNumber(output, "Process ID is "), "There should not be a server node for this build.");
@@ -347,6 +347,14 @@ public void PropertyMSBuildStartupDirectoryOnServer()
347347
output.ShouldContain($@":MSBuildStartupDirectory:{Environment.CurrentDirectory}:");
348348
}
349349

350+
/// <summary>
351+
/// Execute MSBuild with explicit console logger to prevent CI/CD logger auto-detection in test environments.
352+
/// </summary>
353+
private string ExecMSBuildWithConsoleLogger(string projectPath, out bool success)
354+
{
355+
return RunnerUtilities.ExecMSBuild(BuildEnvironmentHelper.Instance.CurrentMSBuildExePath, $"{projectPath} -logger:ConsoleLogger", out success, false, _output);
356+
}
357+
350358
private int ParseNumber(string searchString, string toFind)
351359
{
352360
Regex regex = new(@$"{toFind}(\d+)");

src/MSBuild.UnitTests/PerfLog_Tests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void TestPerfLogEnabledProducedLogFile()
4040
");
4141

4242
string projectPath = Path.Combine(projectFolder.Path, "ClassLibrary.csproj");
43-
string msbuildParameters = "\"" + projectPath + "\"";
43+
string msbuildParameters = "\"" + projectPath + "\" -logger:ConsoleLogger";
4444

4545
RunnerUtilities.ExecMSBuild(msbuildParameters, out bool successfulExit);
4646
successfulExit.ShouldBeTrue();
@@ -76,7 +76,7 @@ public void TestPerfLogDirectoryGetsCreated()
7676
");
7777

7878
string projectPath = Path.Combine(projectFolder.Path, "ClassLibrary.csproj");
79-
string msbuildParameters = "\"" + projectPath + "\"";
79+
string msbuildParameters = "\"" + projectPath + "\" -logger:ConsoleLogger";
8080

8181
Directory.Exists(perfLogPath).ShouldBeFalse();
8282

src/MSBuild.UnitTests/XMake_Tests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3006,7 +3006,9 @@ private string ExecuteMSBuildExeExpectFailure(string projectContents, IDictionar
30063006
}
30073007
}
30083008

3009-
string output = RunnerUtilities.ExecMSBuild($"\"{testProject.ProjectFile}\" {string.Join(" ", arguments)}", out var success, _output);
3009+
// Explicitly use console logger to prevent CI/CD logger auto-detection in test environments
3010+
string allArguments = $"\"{testProject.ProjectFile}\" -logger:ConsoleLogger {string.Join(" ", arguments)}";
3011+
string output = RunnerUtilities.ExecMSBuild(allArguments, out var success, _output);
30103012

30113013
return (success, output);
30123014
}

0 commit comments

Comments
 (0)