From 9276c4e717b6b867ba4c6d799cafff86b7708028 Mon Sep 17 00:00:00 2001 From: YuliiaKovalova <95473390+YuliiaKovalova@users.noreply.github.com> Date: Mon, 11 Dec 2023 11:23:38 +0100 Subject: [PATCH] =?UTF-8?q?=D0=A1hange=20ProperyReassignment=20logged=20me?= =?UTF-8?q?ssage=20type=20(#9494)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Evaluation/Evaluator_Tests.cs | 65 +++++++++++++++++-- src/Build/Evaluation/Evaluator.cs | 31 +++++++-- 2 files changed, 82 insertions(+), 14 deletions(-) diff --git a/src/Build.UnitTests/Evaluation/Evaluator_Tests.cs b/src/Build.UnitTests/Evaluation/Evaluator_Tests.cs index 7868a07761c..44a21a2321f 100644 --- a/src/Build.UnitTests/Evaluation/Evaluator_Tests.cs +++ b/src/Build.UnitTests/Evaluation/Evaluator_Tests.cs @@ -4597,7 +4597,7 @@ public void VerifyMSBuildLogsAMessageWhenLocalPropertyCannotOverrideValueOfGloba public void VerifyPropertyTrackingLoggingDefault() { // Having just environment variables defined should default to nothing being logged except one environment variable read. - this.VerifyPropertyTrackingLoggingScenario( + VerifyPropertyTrackingLoggingScenario( null, logger => { @@ -4616,7 +4616,8 @@ public void VerifyPropertyTrackingLoggingDefault() logger .AllBuildEvents .OfType() - .ShouldBeEmpty(); + .Count() + .ShouldBe(2); logger .AllBuildEvents @@ -4628,7 +4629,7 @@ public void VerifyPropertyTrackingLoggingDefault() [Fact] public void VerifyPropertyTrackingLoggingPropertyReassignment() { - this.VerifyPropertyTrackingLoggingScenario( + VerifyPropertyTrackingLoggingScenario( "1", logger => { @@ -4677,13 +4678,14 @@ public void VerifyPropertyTrackingLoggingNone() logger .AllBuildEvents - .OfType() + .OfType() .ShouldBeEmpty(); logger - .AllBuildEvents - .OfType() - .ShouldBeEmpty(); + .AllBuildEvents + .OfType() + .Count() + .ShouldBe(2); }); } @@ -4919,6 +4921,55 @@ private void VerifyPropertyTrackingLoggingScenario(string envVarValue, Action + /// Log when a property is being assigned a new value. + /// + [Fact] + public void VerifyLogPropertyReassignment() + { + string propertyName = "Prop"; + string propertyOldValue = "OldValue"; + string propertyNewValue = "NewValue"; + string testtargets = ObjectModelHelpers.CleanupFileContents(@$" + + + <{propertyName}>{propertyOldValue} + <{propertyName}>{propertyNewValue} + + + "); + + string tempPath = Path.GetTempPath(); + string targetDirectory = Path.Combine(tempPath, "LogPropertyAssignments"); + string testTargetPath = Path.Combine(targetDirectory, "test.proj"); + + using (TestEnvironment env = TestEnvironment.Create()) + { + env.CreateFolder(targetDirectory); + env.CreateFile(testTargetPath, testtargets); + + MockLogger logger = new() + { + Verbosity = LoggerVerbosity.Diagnostic, + }; + ProjectCollection pc = new(); + pc.RegisterLogger(logger); + Project project = pc.LoadProject(testTargetPath); + + bool result = project.Build(); + result.ShouldBeTrue(); + logger.BuildMessageEvents + .OfType() + .ShouldContain(r => r.PropertyName == propertyName + && r.PreviousValue == propertyOldValue + && r.NewValue == propertyNewValue + && r.Message.StartsWith($"{ + ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword( + "PropertyReassignment", propertyName, propertyNewValue, propertyOldValue, string.Empty)}")); + logger.BuildMessageEvents.ShouldBeOfTypes(new[] { typeof(PropertyReassignmentEventArgs) }); + } + } + #if FEATURE_HTTP_LISTENER /// /// HTTP server code running on a separate thread that expects a connection request diff --git a/src/Build/Evaluation/Evaluator.cs b/src/Build/Evaluation/Evaluator.cs index 3609af082d5..e048e5dd371 100644 --- a/src/Build/Evaluation/Evaluator.cs +++ b/src/Build/Evaluation/Evaluator.cs @@ -1348,13 +1348,30 @@ private void LogPropertyReassignment(P predecessor, P property, string location) if (newValue != oldValue) { - _evaluationLoggingContext.LogComment( - MessageImportance.Low, - "PropertyReassignment", - property.Name, - newValue, - oldValue, - location); + if (ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_10)) + { + var args = new PropertyReassignmentEventArgs( + property.Name, + oldValue, + newValue, + location, + message: null) + { + BuildEventContext = _evaluationLoggingContext.BuildEventContext, + }; + + _evaluationLoggingContext.LogBuildEvent(args); + } + else + { + _evaluationLoggingContext.LogComment( + MessageImportance.Low, + "PropertyReassignment", + property.Name, + newValue, + oldValue, + location); + } } }