diff --git a/src/MSBuild.UnitTests/XMake_Tests.cs b/src/MSBuild.UnitTests/XMake_Tests.cs
index 49c3a8792d5..c309cbde37c 100644
--- a/src/MSBuild.UnitTests/XMake_Tests.cs
+++ b/src/MSBuild.UnitTests/XMake_Tests.cs
@@ -12,6 +12,7 @@
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.Build.CommandLine;
+using Microsoft.Build.Evaluation;
using Microsoft.Build.Framework;
using Microsoft.Build.Logging;
using Microsoft.Build.Shared;
@@ -890,6 +891,7 @@ public void SetConsoleUICulture()
// Restore the current UI culture back to the way it was at the beginning of this unit test.
thisThread.CurrentUICulture = originalUICulture;
+ MSBuildApp.SetConsoleUI();
}
@@ -2605,6 +2607,41 @@ public override bool Execute()
}
}
+ [Theory]
+ [InlineData("", true)]
+ [InlineData("/tl:true", false)]
+ [InlineData("/nologo", false)]
+ [InlineData("/getProperty:p", false)]
+ public void EndToEndVersionMessage(string arguments, bool shouldContainVersionMessage)
+ {
+ using TestEnvironment testEnvironment = UnitTests.TestEnvironment.Create();
+
+ string projectContents = ObjectModelHelpers.CleanupFileContents("""
+
+
+
+
+ """);
+
+ TransientTestProjectWithFiles testProject = testEnvironment.CreateTestProjectWithFiles(projectContents);
+
+ string output = RunnerUtilities.ExecMSBuild($"{arguments} \"{testProject.ProjectFile}\"", out bool success, _output);
+ success.ShouldBeTrue();
+
+ string expectedVersionString =
+ ResourceUtilities.FormatResourceStringStripCodeAndKeyword("MSBuildVersionMessage",
+ ProjectCollection.DisplayVersion, NativeMethodsShared.FrameworkName);
+
+ if (shouldContainVersionMessage)
+ {
+ output.ShouldContain(expectedVersionString);
+ }
+ else
+ {
+ output.ShouldNotContain(expectedVersionString);
+ }
+ }
+
[Theory]
[InlineData("/v:diagnostic", MessageImportance.Low)]
[InlineData("/v:detailed", MessageImportance.Low)]
diff --git a/src/MSBuild/XMake.cs b/src/MSBuild/XMake.cs
index 3fc3238e3d2..7305abef033 100644
--- a/src/MSBuild/XMake.cs
+++ b/src/MSBuild/XMake.cs
@@ -2455,20 +2455,8 @@ private static bool ProcessCommandLineSwitches(
}
#endif
- bool shouldShowLogo = !commandLineSwitches[CommandLineSwitches.ParameterlessSwitch.NoLogo] &&
- !commandLineSwitches.IsParameterizedSwitchSet(CommandLineSwitches.ParameterizedSwitch.Preprocess) &&
- !commandLineSwitches.IsParameterizedSwitchSet(CommandLineSwitches.ParameterizedSwitch.GetProperty) &&
- !commandLineSwitches.IsParameterizedSwitchSet(CommandLineSwitches.ParameterizedSwitch.GetItem) &&
- !commandLineSwitches.IsParameterizedSwitchSet(CommandLineSwitches.ParameterizedSwitch.GetTargetResult) &&
- !commandLineSwitches.IsParameterizedSwitchSet(CommandLineSwitches.ParameterizedSwitch.FeatureAvailability);
-
- // show copyright message if nologo switch is not set
- // NOTE: we heed the nologo switch even if there are switch errors
- if (!recursing && shouldShowLogo)
- {
- DisplayVersionMessage();
- }
-
+ bool useTerminalLogger = ProcessTerminalLoggerConfiguration(commandLineSwitches, out string aggregatedTerminalLoggerParameters);
+ DisplayVersionMessageIfNeeded(recursing, useTerminalLogger, commandLineSwitches);
// Idle priority would prevent the build from proceeding as the user does normal actions.
// This switch is processed early to capture both the command line case (main node should
@@ -2658,8 +2646,6 @@ private static bool ProcessCommandLineSwitches(
outputResultsCache = ProcessOutputResultsCache(commandLineSwitches);
- bool useTerminalLogger = ProcessTerminalLoggerConfiguration(commandLineSwitches, out string aggregatedTerminalLoggerParameters);
-
// figure out which loggers are going to listen to build events
string[][] groupedFileLoggerParameters = commandLineSwitches.GetFileLoggerParameters();
@@ -4465,9 +4451,29 @@ private static void ThrowInvalidToolsVersionInitializationException(IEnumerable<
///
/// Displays the application version message/logo.
///
- private static void DisplayVersionMessage()
+ private static void DisplayVersionMessageIfNeeded(bool recursing, bool useTerminalLogger, CommandLineSwitches commandLineSwitches)
{
- Console.WriteLine(ResourceUtilities.FormatResourceStringStripCodeAndKeyword("MSBuildVersionMessage", ProjectCollection.DisplayVersion, NativeMethods.FrameworkName));
+ if (recursing)
+ {
+ return;
+ }
+
+ // Show the versioning information if the user has not disabled it or msbuild is not running in a mode
+ // where it is not appropriate to show the versioning information (information querying mode that can be plugged into CLI scripts,
+ // terminal logger mode, where we want to display only the most relevant info, while output is not meant for investigation).
+ // NOTE: response files are not reflected in this check. So enabling TL in response file will lead to version message still being shown.
+ bool shouldShowLogo = !commandLineSwitches[CommandLineSwitches.ParameterlessSwitch.NoLogo] &&
+ !commandLineSwitches.IsParameterizedSwitchSet(CommandLineSwitches.ParameterizedSwitch.Preprocess) &&
+ !commandLineSwitches.IsParameterizedSwitchSet(CommandLineSwitches.ParameterizedSwitch.GetProperty) &&
+ !commandLineSwitches.IsParameterizedSwitchSet(CommandLineSwitches.ParameterizedSwitch.GetItem) &&
+ !commandLineSwitches.IsParameterizedSwitchSet(CommandLineSwitches.ParameterizedSwitch.GetTargetResult) &&
+ !commandLineSwitches.IsParameterizedSwitchSet(CommandLineSwitches.ParameterizedSwitch.FeatureAvailability) &&
+ !useTerminalLogger;
+
+ if (shouldShowLogo)
+ {
+ Console.WriteLine(ResourceUtilities.FormatResourceStringStripCodeAndKeyword("MSBuildVersionMessage", ProjectCollection.DisplayVersion, NativeMethods.FrameworkName));
+ }
}
///