From 8d57dfcbcbaf083dbc9a84e4b85a9e05c506fefd Mon Sep 17 00:00:00 2001 From: Kirill Osenkov Date: Tue, 13 Apr 2021 10:54:31 -0700 Subject: [PATCH] Bring back ProjectStarted.GlobalProperties (#6342) Some loggers depended on ProjectStartedEventArgs.GlobalProperties being not null and set. It will take a long time to move them to ProjectEvaluationFinished (needs to bump MSBuild dependency to 16.10). For now log GlobalProperties in both places (ProjectStarted and ProjectEvaluationFinished). Hopefully the deduplication will save us from any significant increase in binlog size. Fixes #6341 --- src/Build/BackEnd/Components/Logging/LoggingService.cs | 9 +++++---- .../Components/Logging/LoggingServiceLogMethods.cs | 8 +++----- src/Build/Evaluation/Evaluator.cs | 6 +----- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/Build/BackEnd/Components/Logging/LoggingService.cs b/src/Build/BackEnd/Components/Logging/LoggingService.cs index a96a169fb18..7f8aa44f50f 100644 --- a/src/Build/BackEnd/Components/Logging/LoggingService.cs +++ b/src/Build/BackEnd/Components/Logging/LoggingService.cs @@ -1170,10 +1170,11 @@ internal void InjectNonSerializedData(LogMessagePacket loggingPacket) { ErrorUtilities.VerifyThrow(_configCache.Value.HasConfiguration(projectStartedEventArgs.ProjectId), "Cannot find the project configuration while injecting non-serialized data from out-of-proc node."); BuildRequestConfiguration buildRequestConfiguration = _configCache.Value[projectStartedEventArgs.ProjectId]; - if (!IncludeEvaluationPropertiesAndItems) - { - s_projectStartedEventArgsGlobalProperties.Value.SetValue(projectStartedEventArgs, buildRequestConfiguration.GlobalProperties.ToDictionary(), null); - } + + // Always log GlobalProperties on ProjectStarted for compatibility. + // There are loggers that depend on it being not-null and always set. + // See https://github.com/dotnet/msbuild/issues/6341 for details. + s_projectStartedEventArgsGlobalProperties.Value.SetValue(projectStartedEventArgs, buildRequestConfiguration.GlobalProperties.ToDictionary(), index: null); s_projectStartedEventArgsToolsVersion.Value.SetValue(projectStartedEventArgs, buildRequestConfiguration.ToolsVersion, null); } diff --git a/src/Build/BackEnd/Components/Logging/LoggingServiceLogMethods.cs b/src/Build/BackEnd/Components/Logging/LoggingServiceLogMethods.cs index 6dcf39925d2..4e104910a97 100644 --- a/src/Build/BackEnd/Components/Logging/LoggingServiceLogMethods.cs +++ b/src/Build/BackEnd/Components/Logging/LoggingServiceLogMethods.cs @@ -595,11 +595,9 @@ public BuildEventContext LogProjectStarted(BuildEventContext nodeBuildEventConte ErrorUtilities.VerifyThrow(_configCache.Value.HasConfiguration(projectInstanceId), "Cannot find the project configuration while injecting non-serialized data from out-of-proc node."); var buildRequestConfiguration = _configCache.Value[projectInstanceId]; - IDictionary globalProperties = null; - if (!IncludeEvaluationPropertiesAndItems) - { - globalProperties = buildRequestConfiguration.GlobalProperties.ToDictionary(); - } + // Always log GlobalProperties on ProjectStarted + // See https://github.com/dotnet/msbuild/issues/6341 for details + IDictionary globalProperties = buildRequestConfiguration.GlobalProperties.ToDictionary(); var buildEvent = new ProjectStartedEventArgs ( diff --git a/src/Build/Evaluation/Evaluator.cs b/src/Build/Evaluation/Evaluator.cs index 3c88d31cf0e..fdc0ec6a0ec 100644 --- a/src/Build/Evaluation/Evaluator.cs +++ b/src/Build/Evaluation/Evaluator.cs @@ -785,11 +785,7 @@ private void Evaluate() if (this._evaluationLoggingContext.LoggingService.IncludeEvaluationPropertiesAndItems) { - if (_data.GlobalPropertiesDictionary.Count > 0) - { - globalProperties = _data.GlobalPropertiesDictionary; - } - + globalProperties = _data.GlobalPropertiesDictionary; properties = _data.Properties; items = _data.Items; }