diff --git a/src/Build.UnitTests/TerminalLoggerConfiguration_Tests.cs b/src/Build.UnitTests/TerminalLoggerConfiguration_Tests.cs
index 6266cb6e4c7..fae6fbcbeb6 100644
--- a/src/Build.UnitTests/TerminalLoggerConfiguration_Tests.cs
+++ b/src/Build.UnitTests/TerminalLoggerConfiguration_Tests.cs
@@ -28,10 +28,6 @@ public TerminalLoggerConfiguration_Tests(ITestOutputHelper output)
{
_env = TestEnvironment.Create(output);
- // Ignore environment variables that may have been set by the environment where the tests are running.
- _env.SetEnvironmentVariable("MSBUILDLIVELOGGER", null);
- _env.SetEnvironmentVariable("MSBUILDTERMINALLOGGER", null);
-
TransientTestFolder logFolder = _env.CreateFolder(createFolder: true);
TransientTestFile projectFile = _env.CreateFile(logFolder, "myProj.proj", $"""
diff --git a/src/MSBuild.UnitTests/MSBuildServer_Tests.cs b/src/MSBuild.UnitTests/MSBuildServer_Tests.cs
index 16fbed5a461..2de493e68b9 100644
--- a/src/MSBuild.UnitTests/MSBuildServer_Tests.cs
+++ b/src/MSBuild.UnitTests/MSBuildServer_Tests.cs
@@ -68,7 +68,7 @@ public class MSBuildServer_Tests : IDisposable
-
+
";
private static string sleepingTaskContentsFormat = @$"
@@ -313,8 +313,8 @@ public void PropertyMSBuildStartupDirectoryOnServer()
-
-
+
+
";
diff --git a/src/UnitTests.Shared/TestEnvironment.cs b/src/UnitTests.Shared/TestEnvironment.cs
index 86e85d3cd51..d961178b298 100644
--- a/src/UnitTests.Shared/TestEnvironment.cs
+++ b/src/UnitTests.Shared/TestEnvironment.cs
@@ -53,6 +53,10 @@ public static TestEnvironment Create(ITestOutputHelper output = null, bool ignor
env.WithInvariant(new BuildFailureLogInvariant());
}
+ // Clear these two environment variables first in case pre-setting affects the test.
+ env.SetEnvironmentVariable("MSBUILDLIVELOGGER", null);
+ env.SetEnvironmentVariable("MSBUILDTERMINALLOGGER", null);
+
return env;
}
@@ -83,10 +87,10 @@ private void Cleanup()
{
_disposed = true;
- // Reset test variants
- foreach (var variant in _variants)
+ // Reset test variants in reverse order to get back to original state.
+ for (int i = _variants.Count - 1; i >= 0; i--)
{
- variant.Revert();
+ _variants[i].Revert();
}
// Assert invariants