From c65169d2c19b9f74b7943febc8bcedaffc944358 Mon Sep 17 00:00:00 2001 From: Ladi Prosek Date: Fri, 10 May 2024 17:04:40 +0200 Subject: [PATCH 1/9] Log output task parameters as structured events --- .../IntrinsicTasks/ItemGroupIntrinsicTask.cs | 2 ++ .../IntrinsicTasks/ItemGroupLoggingHelper.cs | 4 +++ .../RequestBuilder/TargetUpToDateChecker.cs | 2 ++ .../TaskExecutionHost/TaskExecutionHost.cs | 33 +++++++++++++++-- .../BinaryLogger/BuildEventArgsReader.cs | 2 ++ .../BinaryLogger/BuildEventArgsWriter.cs | 1 + src/Framework/TaskParameterEventArgs.cs | 36 +++++++++++++++++++ 7 files changed, 78 insertions(+), 2 deletions(-) diff --git a/src/Build/BackEnd/Components/RequestBuilder/IntrinsicTasks/ItemGroupIntrinsicTask.cs b/src/Build/BackEnd/Components/RequestBuilder/IntrinsicTasks/ItemGroupIntrinsicTask.cs index 08cc3e9f5e0..826f4216c92 100644 --- a/src/Build/BackEnd/Components/RequestBuilder/IntrinsicTasks/ItemGroupIntrinsicTask.cs +++ b/src/Build/BackEnd/Components/RequestBuilder/IntrinsicTasks/ItemGroupIntrinsicTask.cs @@ -225,6 +225,7 @@ private void ExecuteAdd(ProjectItemGroupTaskItemInstance child, ItemBucket bucke ItemGroupLoggingHelper.LogTaskParameter( LoggingContext, TaskParameterMessageKind.AddItem, + parameterName: null, child.ItemType, itemsToAdd, logItemMetadata: true, @@ -269,6 +270,7 @@ private void ExecuteRemove(ProjectItemGroupTaskItemInstance child, ItemBucket bu ItemGroupLoggingHelper.LogTaskParameter( LoggingContext, TaskParameterMessageKind.RemoveItem, + parameterName: null, child.ItemType, itemsToRemove, logItemMetadata: true, diff --git a/src/Build/BackEnd/Components/RequestBuilder/IntrinsicTasks/ItemGroupLoggingHelper.cs b/src/Build/BackEnd/Components/RequestBuilder/IntrinsicTasks/ItemGroupLoggingHelper.cs index df32111f095..c9aabed4443 100644 --- a/src/Build/BackEnd/Components/RequestBuilder/IntrinsicTasks/ItemGroupLoggingHelper.cs +++ b/src/Build/BackEnd/Components/RequestBuilder/IntrinsicTasks/ItemGroupLoggingHelper.cs @@ -255,6 +255,7 @@ private static void AppendStringFromParameterValue(ReuseableStringBuilder sb, ob internal static void LogTaskParameter( LoggingContext loggingContext, TaskParameterMessageKind messageKind, + string parameterName, string itemType, IList items, bool logItemMetadata, @@ -263,6 +264,7 @@ internal static void LogTaskParameter( var args = CreateTaskParameterEventArgs( loggingContext.BuildEventContext, messageKind, + parameterName, itemType, items, logItemMetadata, @@ -276,6 +278,7 @@ internal static void LogTaskParameter( internal static TaskParameterEventArgs CreateTaskParameterEventArgs( BuildEventContext buildEventContext, TaskParameterMessageKind messageKind, + string parameterName, string itemType, IList items, bool logItemMetadata, @@ -290,6 +293,7 @@ internal static TaskParameterEventArgs CreateTaskParameterEventArgs( var args = new TaskParameterEventArgs( messageKind, + parameterName, itemType, items, logItemMetadata, diff --git a/src/Build/BackEnd/Components/RequestBuilder/TargetUpToDateChecker.cs b/src/Build/BackEnd/Components/RequestBuilder/TargetUpToDateChecker.cs index 4b40715d67b..3be6694ed91 100644 --- a/src/Build/BackEnd/Components/RequestBuilder/TargetUpToDateChecker.cs +++ b/src/Build/BackEnd/Components/RequestBuilder/TargetUpToDateChecker.cs @@ -368,6 +368,7 @@ private void LogUniqueInputsAndOutputs() var args = ItemGroupLoggingHelper.CreateTaskParameterEventArgs( _buildEventContext, TaskParameterMessageKind.SkippedTargetInputs, + parameterName: null, itemType: null, _uniqueTargetInputs.Keys.ToArray(), logItemMetadata: false, @@ -377,6 +378,7 @@ private void LogUniqueInputsAndOutputs() args = ItemGroupLoggingHelper.CreateTaskParameterEventArgs( _buildEventContext, TaskParameterMessageKind.SkippedTargetOutputs, + parameterName: null, itemType: null, _uniqueTargetOutputs.Keys.ToArray(), logItemMetadata: false, diff --git a/src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs b/src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs index fdff89eb618..c3ccda629da 100644 --- a/src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs +++ b/src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs @@ -1321,6 +1321,7 @@ private bool InternalSetTaskParameter( _taskLoggingContext, TaskParameterMessageKind.TaskInput, parameter.Name, + parameter.Name, parameterValueAsList ?? new object[] { parameterValue }, parameter.LogItemMetadata); } @@ -1429,6 +1430,7 @@ static IEnumerable> EnumerateMetadata(IDictionary c ItemGroupLoggingHelper.LogTaskParameter( _taskLoggingContext, TaskParameterMessageKind.TaskOutput, + parameter.Name, outputTargetName, outputs, parameter.LogItemMetadata); @@ -1470,7 +1472,20 @@ static IEnumerable> EnumerateMetadata(IDictionary c var outputString = joinedOutputs.ToString(); if (LogTaskInputs && !_taskLoggingContext.LoggingService.OnlyLogCriticalEvents) { - _taskLoggingContext.LogComment(MessageImportance.Low, "OutputPropertyLogMessage", outputTargetName, outputString); + if (ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_12)) + { + ItemGroupLoggingHelper.LogTaskParameter( + _taskLoggingContext, + TaskParameterMessageKind.TaskOutput, + parameter.Name, + parameter.Name, + new object[] { outputString }, + parameter.LogItemMetadata); + } + else + { + _taskLoggingContext.LogComment(MessageImportance.Low, "OutputPropertyLogMessage", outputTargetName, outputString); + } } _batchBucket.Lookup.SetProperty(ProjectPropertyInstance.Create(outputTargetName, outputString, parameterLocation, _projectInstance.IsImmutable)); @@ -1505,6 +1520,7 @@ private void GatherArrayStringAndValueOutputs(bool outputTargetIsItem, string ou ItemGroupLoggingHelper.LogTaskParameter( _taskLoggingContext, TaskParameterMessageKind.TaskOutput, + parameter.Name, outputTargetName, outputs, parameter.LogItemMetadata); @@ -1539,7 +1555,20 @@ private void GatherArrayStringAndValueOutputs(bool outputTargetIsItem, string ou var outputString = joinedOutputs.ToString(); if (LogTaskInputs && !_taskLoggingContext.LoggingService.OnlyLogCriticalEvents) { - _taskLoggingContext.LogComment(MessageImportance.Low, "OutputPropertyLogMessage", outputTargetName, outputString); + if (ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_12)) + { + ItemGroupLoggingHelper.LogTaskParameter( + _taskLoggingContext, + TaskParameterMessageKind.TaskOutput, + parameter.Name, + parameter.Name, + new object[] { outputString }, + parameter.LogItemMetadata); + } + else + { + _taskLoggingContext.LogComment(MessageImportance.Low, "OutputPropertyLogMessage", outputTargetName, outputString); + } } _batchBucket.Lookup.SetProperty(ProjectPropertyInstance.Create(outputTargetName, outputString, parameterLocation, _projectInstance.IsImmutable)); diff --git a/src/Build/Logging/BinaryLogger/BuildEventArgsReader.cs b/src/Build/Logging/BinaryLogger/BuildEventArgsReader.cs index 03ce7bed76c..7b3fc3a3a05 100644 --- a/src/Build/Logging/BinaryLogger/BuildEventArgsReader.cs +++ b/src/Build/Logging/BinaryLogger/BuildEventArgsReader.cs @@ -1022,10 +1022,12 @@ private BuildEventArgs ReadTaskParameterEventArgs() var kind = (TaskParameterMessageKind)ReadInt32(); var itemType = ReadDeduplicatedString(); var items = ReadTaskItemList() as IList; + var parameterName = ReadDeduplicatedString(); var e = ItemGroupLoggingHelper.CreateTaskParameterEventArgs( fields.BuildEventContext, kind, + parameterName, itemType, items, logItemMetadata: true, diff --git a/src/Build/Logging/BinaryLogger/BuildEventArgsWriter.cs b/src/Build/Logging/BinaryLogger/BuildEventArgsWriter.cs index 0c5c82846b3..fba322dc171 100644 --- a/src/Build/Logging/BinaryLogger/BuildEventArgsWriter.cs +++ b/src/Build/Logging/BinaryLogger/BuildEventArgsWriter.cs @@ -571,6 +571,7 @@ private BinaryLogRecordKind Write(TaskParameterEventArgs e) Write((int)e.Kind); WriteDeduplicatedString(e.ItemType); WriteTaskItemList(e.Items, e.LogItemMetadata); + WriteDeduplicatedString(e.ParameterName); if (e.Kind == TaskParameterMessageKind.AddItem || e.Kind == TaskParameterMessageKind.TaskOutput) { diff --git a/src/Framework/TaskParameterEventArgs.cs b/src/Framework/TaskParameterEventArgs.cs index 7aa294f828c..88f09bf6b58 100644 --- a/src/Framework/TaskParameterEventArgs.cs +++ b/src/Framework/TaskParameterEventArgs.cs @@ -34,6 +34,7 @@ public class TaskParameterEventArgs : BuildMessageEventArgs /// public TaskParameterEventArgs( TaskParameterMessageKind kind, + string parameterName, string itemType, IList items, bool logItemMetadata, @@ -41,14 +42,49 @@ public TaskParameterEventArgs( : base(null, null, null, MessageImportance.Low, eventTimestamp) { Kind = kind; + ParameterName = parameterName; ItemType = itemType; Items = items; LogItemMetadata = logItemMetadata; } + /// + /// Creates an instance of this class for the given task parameter. + /// + public TaskParameterEventArgs( + TaskParameterMessageKind kind, + string itemType, + IList items, + bool logItemMetadata, + DateTime eventTimestamp) + : this(kind, parameterName: null, itemType, items, logItemMetadata, eventTimestamp) + { } + + /// + /// The kind of event represented by this instance. + /// public TaskParameterMessageKind Kind { get; private set; } + + /// + /// The name of the item being manipulated, e.g. "Compile". For backward compatibility, this property has the same value + /// as in cases where the operation does not manipulate any items, such as when representing + /// task inputs or task outputs assigned to properties. + /// public string ItemType { get; private set; } + + /// + /// The name of the parameter if is or . + /// + public string ParameterName { get; private set; } + + /// + /// The values being manipulated (added, removed, passed to/from task). + /// public IList Items { get; private set; } + + /// + /// True if the string should include metadata. + /// public bool LogItemMetadata { get; private set; } /// From e363350f13fb285cf7093c05fe7bd8dd5b23fb47 Mon Sep 17 00:00:00 2001 From: Ladi Prosek Date: Fri, 10 May 2024 17:26:33 +0200 Subject: [PATCH 2/9] Use TaskParameterEventArgs.ParameterName in BuildCheck --- .../Infrastructure/BuildEventsProcessor.cs | 2 +- .../TaskInvocationAnalysisDataTests.cs | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Build/BuildCheck/Infrastructure/BuildEventsProcessor.cs b/src/Build/BuildCheck/Infrastructure/BuildEventsProcessor.cs index cf2bae57bad..aa804067b60 100644 --- a/src/Build/BuildCheck/Infrastructure/BuildEventsProcessor.cs +++ b/src/Build/BuildCheck/Infrastructure/BuildEventsProcessor.cs @@ -151,7 +151,7 @@ internal void ProcessTaskParameterEventArgs( { // Add the parameter name and value to the matching entry in _tasksBeingExecuted. Parameters come typed as IList // but it's more natural to pass them as scalar values so we unwrap one-element lists. - string parameterName = taskParameterEventArgs.ItemType; + string parameterName = taskParameterEventArgs.ParameterName; object? parameterValue = taskParameterEventArgs.Items?.Count switch { 1 => taskParameterEventArgs.Items[0], diff --git a/src/BuildCheck.UnitTests/TaskInvocationAnalysisDataTests.cs b/src/BuildCheck.UnitTests/TaskInvocationAnalysisDataTests.cs index bd93ddcf927..67d7cf784ef 100644 --- a/src/BuildCheck.UnitTests/TaskInvocationAnalysisDataTests.cs +++ b/src/BuildCheck.UnitTests/TaskInvocationAnalysisDataTests.cs @@ -114,15 +114,17 @@ public void ReportsSimpleTaskParameters() data.Parameters["Text"].Value.ShouldBe("Hello"); } - [Fact] - public void ReportsComplexTaskParameters() + [Theory] + [InlineData("")] + [InlineData("")] + public void ReportsComplexTaskParameters(string outputElement) { - BuildProject(""" + BuildProject($""" - + {outputElement} """); @@ -139,9 +141,8 @@ public void ReportsComplexTaskParameters() listValue[1]!.ShouldBeAssignableTo(typeof(ITaskItem)); ((ITaskItem)listValue[0]!).ItemSpec.ShouldBe("item1"); ((ITaskItem)listValue[1]!).ItemSpec.ShouldBe("item2"); - - // The name of the parameter would ideally be "CombinedPaths" but we don't seem to be currently logging it. - data.Parameters["OutputDirectories"].IsOutput.ShouldBe(true); + data.Parameters["CombinedPaths"].IsOutput.ShouldBe(true); + data.Parameters["CombinedPaths"].Value.ShouldNotBeNull(); } } } From f128bffd1edabadd1c070325a7f7673497aa06fc Mon Sep 17 00:00:00 2001 From: Ladi Prosek Date: Mon, 13 May 2024 16:14:53 +0200 Subject: [PATCH 3/9] Fix serialization and bump binlog version --- .../BuildEventArgsSerialization_Tests.cs | 3 ++- src/Build/Logging/BinaryLogger/BinaryLogger.cs | 4 +++- src/Framework/TaskParameterEventArgs.cs | 12 +++++++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Build.UnitTests/BuildEventArgsSerialization_Tests.cs b/src/Build.UnitTests/BuildEventArgsSerialization_Tests.cs index cb60a9f2d42..d6cbcf5ac8e 100644 --- a/src/Build.UnitTests/BuildEventArgsSerialization_Tests.cs +++ b/src/Build.UnitTests/BuildEventArgsSerialization_Tests.cs @@ -650,12 +650,13 @@ public void RoundtripTaskParameterEventArgs() new TaskItemData("ItemSpec1", null), new TaskItemData("ItemSpec2", Enumerable.Range(1,3).ToDictionary(i => i.ToString(), i => i.ToString() + "value")) }; - var args = new TaskParameterEventArgs(TaskParameterMessageKind.TaskOutput, "ItemName", items, true, DateTime.MinValue); + var args = new TaskParameterEventArgs(TaskParameterMessageKind.TaskOutput, "ParameterName", "ItemName", items, true, DateTime.MinValue); args.LineNumber = 265; args.ColumnNumber = 6; Roundtrip(args, e => e.Kind.ToString(), + e => e.ParameterName, e => e.ItemType, e => e.LogItemMetadata.ToString(), e => e.LineNumber.ToString(), diff --git a/src/Build/Logging/BinaryLogger/BinaryLogger.cs b/src/Build/Logging/BinaryLogger/BinaryLogger.cs index a7b005a1925..99887549606 100644 --- a/src/Build/Logging/BinaryLogger/BinaryLogger.cs +++ b/src/Build/Logging/BinaryLogger/BinaryLogger.cs @@ -71,6 +71,8 @@ public sealed class BinaryLogger : ILogger // - GeneratedFileUsedEventArgs exposed for brief period of time (so let's continue with 20) // version 20: // - TaskStartedEventArgs: Added TaskAssemblyLocation property + // version 21: + // - TaskParameterEventArgs: Added ParameterName property // This should be never changed. // The minimum version of the binary log reader that can read log of above version. @@ -78,7 +80,7 @@ public sealed class BinaryLogger : ILogger // The current version of the binary log representation. // Changes with each update of the binary log format. - internal const int FileFormatVersion = 20; + internal const int FileFormatVersion = 21; // The minimum version of the binary log reader that can read log of above version. // This should be changed only when the binary log format is changed in a way that would prevent it from being diff --git a/src/Framework/TaskParameterEventArgs.cs b/src/Framework/TaskParameterEventArgs.cs index 88f09bf6b58..04fb6a8aec1 100644 --- a/src/Framework/TaskParameterEventArgs.cs +++ b/src/Framework/TaskParameterEventArgs.cs @@ -65,6 +65,11 @@ public TaskParameterEventArgs( /// public TaskParameterMessageKind Kind { get; private set; } + /// + /// The name of the parameter if is or . + /// + public string ParameterName { get; private set; } + /// /// The name of the item being manipulated, e.g. "Compile". For backward compatibility, this property has the same value /// as in cases where the operation does not manipulate any items, such as when representing @@ -72,11 +77,6 @@ public TaskParameterEventArgs( /// public string ItemType { get; private set; } - /// - /// The name of the parameter if is or . - /// - public string ParameterName { get; private set; } - /// /// The values being manipulated (added, removed, passed to/from task). /// @@ -121,6 +121,7 @@ internal override void CreateFromStream(BinaryReader reader, int version) RawTimestamp = reader.ReadTimestamp(); BuildEventContext = reader.ReadOptionalBuildEventContext(); Kind = (TaskParameterMessageKind)reader.Read7BitEncodedInt(); + ParameterName = reader.ReadOptionalString(); ItemType = reader.ReadOptionalString(); LineNumber = reader.Read7BitEncodedInt(); ColumnNumber = reader.Read7BitEncodedInt(); @@ -170,6 +171,7 @@ internal override void WriteToStream(BinaryWriter writer) writer.WriteTimestamp(RawTimestamp); writer.WriteOptionalBuildEventContext(BuildEventContext); writer.Write7BitEncodedInt((int)Kind); + writer.WriteOptionalString(ParameterName); writer.WriteOptionalString(ItemType); writer.Write7BitEncodedInt(LineNumber); writer.Write7BitEncodedInt(ColumnNumber); From 423f7bb43afa6d9a5b2a70ec7dc7fe00c4cbdbe8 Mon Sep 17 00:00:00 2001 From: Ladi Prosek Date: Wed, 15 May 2024 10:56:19 +0200 Subject: [PATCH 4/9] Update ChangeWaves.md --- documentation/wiki/ChangeWaves.md | 1 + 1 file changed, 1 insertion(+) diff --git a/documentation/wiki/ChangeWaves.md b/documentation/wiki/ChangeWaves.md index 7744d96a090..c30d03cea0f 100644 --- a/documentation/wiki/ChangeWaves.md +++ b/documentation/wiki/ChangeWaves.md @@ -27,6 +27,7 @@ A wave of features is set to "rotate out" (i.e. become standard functionality) t - [Log TaskParameterEvent for scalar parameters](https://github.com/dotnet/msbuild/pull/9908) - [Convert.ToString during a property evaluation uses the InvariantCulture for all types](https://github.com/dotnet/msbuild/pull/9874) - [Fix oversharing of build results in ResultsCache](https://github.com/dotnet/msbuild/pull/9987) +- [Add ParameterName and PropertyName to TaskParameterEventArgs](https://github.com/dotnet/msbuild/pull/10130) ### 17.10 - [AppDomain configuration is serialized without using BinFmt](https://github.com/dotnet/msbuild/pull/9320) - feature can be opted out only if [BinaryFormatter](https://learn.microsoft.com/en-us/dotnet/api/system.runtime.serialization.formatters.binary.binaryformatter) is allowed at runtime by editing `MSBuild.runtimeconfig.json` From 4ac228b120aee8ea080529b39906141552c28180 Mon Sep 17 00:00:00 2001 From: Ladi Prosek Date: Wed, 15 May 2024 10:57:24 +0200 Subject: [PATCH 5/9] Add PropertyName to TaskParameterEventArgs --- .../BuildEventArgsSerialization_Tests.cs | 3 ++- .../IntrinsicTasks/ItemGroupIntrinsicTask.cs | 2 ++ .../IntrinsicTasks/ItemGroupLoggingHelper.cs | 21 +++++++++------- .../RequestBuilder/TargetUpToDateChecker.cs | 2 ++ .../TaskExecutionHost/TaskExecutionHost.cs | 25 +++++++++++-------- .../BinaryLogger/BuildEventArgsReader.cs | 2 ++ .../BinaryLogger/BuildEventArgsWriter.cs | 1 + src/Build/Resources/Strings.resx | 3 +++ src/Build/Resources/xlf/Strings.cs.xlf | 5 ++++ src/Build/Resources/xlf/Strings.de.xlf | 5 ++++ src/Build/Resources/xlf/Strings.es.xlf | 5 ++++ src/Build/Resources/xlf/Strings.fr.xlf | 5 ++++ src/Build/Resources/xlf/Strings.it.xlf | 5 ++++ src/Build/Resources/xlf/Strings.ja.xlf | 5 ++++ src/Build/Resources/xlf/Strings.ko.xlf | 5 ++++ src/Build/Resources/xlf/Strings.pl.xlf | 5 ++++ src/Build/Resources/xlf/Strings.pt-BR.xlf | 5 ++++ src/Build/Resources/xlf/Strings.ru.xlf | 5 ++++ src/Build/Resources/xlf/Strings.tr.xlf | 5 ++++ src/Build/Resources/xlf/Strings.zh-Hans.xlf | 5 ++++ src/Build/Resources/xlf/Strings.zh-Hant.xlf | 5 ++++ src/Framework/TaskParameterEventArgs.cs | 20 +++++++++++---- 22 files changed, 119 insertions(+), 25 deletions(-) diff --git a/src/Build.UnitTests/BuildEventArgsSerialization_Tests.cs b/src/Build.UnitTests/BuildEventArgsSerialization_Tests.cs index d6cbcf5ac8e..c391c4cd87a 100644 --- a/src/Build.UnitTests/BuildEventArgsSerialization_Tests.cs +++ b/src/Build.UnitTests/BuildEventArgsSerialization_Tests.cs @@ -650,13 +650,14 @@ public void RoundtripTaskParameterEventArgs() new TaskItemData("ItemSpec1", null), new TaskItemData("ItemSpec2", Enumerable.Range(1,3).ToDictionary(i => i.ToString(), i => i.ToString() + "value")) }; - var args = new TaskParameterEventArgs(TaskParameterMessageKind.TaskOutput, "ParameterName", "ItemName", items, true, DateTime.MinValue); + var args = new TaskParameterEventArgs(TaskParameterMessageKind.TaskOutput, "ParameterName", "PropertyName", "ItemName", items, true, DateTime.MinValue); args.LineNumber = 265; args.ColumnNumber = 6; Roundtrip(args, e => e.Kind.ToString(), e => e.ParameterName, + e => e.PropertyName, e => e.ItemType, e => e.LogItemMetadata.ToString(), e => e.LineNumber.ToString(), diff --git a/src/Build/BackEnd/Components/RequestBuilder/IntrinsicTasks/ItemGroupIntrinsicTask.cs b/src/Build/BackEnd/Components/RequestBuilder/IntrinsicTasks/ItemGroupIntrinsicTask.cs index 826f4216c92..5335ec2f45c 100644 --- a/src/Build/BackEnd/Components/RequestBuilder/IntrinsicTasks/ItemGroupIntrinsicTask.cs +++ b/src/Build/BackEnd/Components/RequestBuilder/IntrinsicTasks/ItemGroupIntrinsicTask.cs @@ -226,6 +226,7 @@ private void ExecuteAdd(ProjectItemGroupTaskItemInstance child, ItemBucket bucke LoggingContext, TaskParameterMessageKind.AddItem, parameterName: null, + propertyName: null, child.ItemType, itemsToAdd, logItemMetadata: true, @@ -271,6 +272,7 @@ private void ExecuteRemove(ProjectItemGroupTaskItemInstance child, ItemBucket bu LoggingContext, TaskParameterMessageKind.RemoveItem, parameterName: null, + propertyName: null, child.ItemType, itemsToRemove, logItemMetadata: true, diff --git a/src/Build/BackEnd/Components/RequestBuilder/IntrinsicTasks/ItemGroupLoggingHelper.cs b/src/Build/BackEnd/Components/RequestBuilder/IntrinsicTasks/ItemGroupLoggingHelper.cs index c9aabed4443..deae62102f0 100644 --- a/src/Build/BackEnd/Components/RequestBuilder/IntrinsicTasks/ItemGroupLoggingHelper.cs +++ b/src/Build/BackEnd/Components/RequestBuilder/IntrinsicTasks/ItemGroupLoggingHelper.cs @@ -10,6 +10,7 @@ #endif using Microsoft.Build.BackEnd.Logging; using Microsoft.Build.Collections; +using Microsoft.Build.Execution; using Microsoft.Build.Framework; using Microsoft.Build.Shared; @@ -35,6 +36,7 @@ internal static class ItemGroupLoggingHelper internal static string ItemGroupIncludeLogMessagePrefix = ResourceUtilities.GetResourceString("ItemGroupIncludeLogMessagePrefix"); internal static string ItemGroupRemoveLogMessage = ResourceUtilities.GetResourceString("ItemGroupRemoveLogMessage"); internal static string OutputItemParameterMessagePrefix = ResourceUtilities.GetResourceString("OutputItemParameterMessagePrefix"); + internal static string OutputPropertyLogMessagePrefix = ResourceUtilities.GetResourceString("OutputPropertyLogMessagePrefix"); internal static string TaskParameterPrefix = ResourceUtilities.GetResourceString("TaskParameterPrefix"); internal static string SkipTargetUpToDateInputs = ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("SkipTargetUpToDateInputs", string.Empty); internal static string SkipTargetUpToDateOutputs = ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("SkipTargetUpToDateOutputs", string.Empty); @@ -256,6 +258,7 @@ internal static void LogTaskParameter( LoggingContext loggingContext, TaskParameterMessageKind messageKind, string parameterName, + string propertyName, string itemType, IList items, bool logItemMetadata, @@ -265,6 +268,7 @@ internal static void LogTaskParameter( loggingContext.BuildEventContext, messageKind, parameterName, + propertyName, itemType, items, logItemMetadata, @@ -279,6 +283,7 @@ internal static TaskParameterEventArgs CreateTaskParameterEventArgs( BuildEventContext buildEventContext, TaskParameterMessageKind messageKind, string parameterName, + string propertyName, string itemType, IList items, bool logItemMetadata, @@ -294,6 +299,7 @@ internal static TaskParameterEventArgs CreateTaskParameterEventArgs( var args = new TaskParameterEventArgs( messageKind, parameterName, + propertyName, itemType, items, logItemMetadata, @@ -359,26 +365,23 @@ private static void CreateItemsSnapshot(ref IList items) #endif internal static string GetTaskParameterText(TaskParameterEventArgs args) - => GetTaskParameterText(args.Kind, args.ItemType, args.Items, args.LogItemMetadata); - - internal static string GetTaskParameterText(TaskParameterMessageKind messageKind, string itemType, IList items, bool logItemMetadata) { - var resourceText = messageKind switch + var resourceText = args.Kind switch { TaskParameterMessageKind.AddItem => ItemGroupIncludeLogMessagePrefix, TaskParameterMessageKind.RemoveItem => ItemGroupRemoveLogMessage, TaskParameterMessageKind.TaskInput => TaskParameterPrefix, - TaskParameterMessageKind.TaskOutput => OutputItemParameterMessagePrefix, + TaskParameterMessageKind.TaskOutput => args.PropertyName is null ? OutputItemParameterMessagePrefix : OutputPropertyLogMessagePrefix, TaskParameterMessageKind.SkippedTargetInputs => SkipTargetUpToDateInputs, TaskParameterMessageKind.SkippedTargetOutputs => SkipTargetUpToDateOutputs, - _ => throw new NotImplementedException($"Unsupported {nameof(TaskParameterMessageKind)} value: {messageKind}") + _ => throw new NotImplementedException($"Unsupported {nameof(TaskParameterMessageKind)} value: {args.Kind}") }; var itemGroupText = GetParameterText( resourceText, - itemType, - items, - logItemMetadata); + args.PropertyName ?? args.ItemType, + args.Items, + args.LogItemMetadata); return itemGroupText; } } diff --git a/src/Build/BackEnd/Components/RequestBuilder/TargetUpToDateChecker.cs b/src/Build/BackEnd/Components/RequestBuilder/TargetUpToDateChecker.cs index 3be6694ed91..9940131c9e9 100644 --- a/src/Build/BackEnd/Components/RequestBuilder/TargetUpToDateChecker.cs +++ b/src/Build/BackEnd/Components/RequestBuilder/TargetUpToDateChecker.cs @@ -369,6 +369,7 @@ private void LogUniqueInputsAndOutputs() _buildEventContext, TaskParameterMessageKind.SkippedTargetInputs, parameterName: null, + propertyName: null, itemType: null, _uniqueTargetInputs.Keys.ToArray(), logItemMetadata: false, @@ -379,6 +380,7 @@ private void LogUniqueInputsAndOutputs() _buildEventContext, TaskParameterMessageKind.SkippedTargetOutputs, parameterName: null, + propertyName: null, itemType: null, _uniqueTargetOutputs.Keys.ToArray(), logItemMetadata: false, diff --git a/src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs b/src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs index c3ccda629da..bacc0ad5914 100644 --- a/src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs +++ b/src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs @@ -1320,8 +1320,9 @@ private bool InternalSetTaskParameter( ItemGroupLoggingHelper.LogTaskParameter( _taskLoggingContext, TaskParameterMessageKind.TaskInput, - parameter.Name, - parameter.Name, + parameterName: parameter.Name, + propertyName: null, + itemType: parameter.Name, parameterValueAsList ?? new object[] { parameterValue }, parameter.LogItemMetadata); } @@ -1430,8 +1431,9 @@ static IEnumerable> EnumerateMetadata(IDictionary c ItemGroupLoggingHelper.LogTaskParameter( _taskLoggingContext, TaskParameterMessageKind.TaskOutput, - parameter.Name, - outputTargetName, + parameterName: parameter.Name, + propertyName: null, + itemType: outputTargetName, outputs, parameter.LogItemMetadata); } @@ -1477,8 +1479,9 @@ static IEnumerable> EnumerateMetadata(IDictionary c ItemGroupLoggingHelper.LogTaskParameter( _taskLoggingContext, TaskParameterMessageKind.TaskOutput, - parameter.Name, - parameter.Name, + parameterName: parameter.Name, + propertyName: outputTargetName, + itemType: null, new object[] { outputString }, parameter.LogItemMetadata); } @@ -1520,8 +1523,9 @@ private void GatherArrayStringAndValueOutputs(bool outputTargetIsItem, string ou ItemGroupLoggingHelper.LogTaskParameter( _taskLoggingContext, TaskParameterMessageKind.TaskOutput, - parameter.Name, - outputTargetName, + parameterName: parameter.Name, + propertyName: null, + itemType: outputTargetName, outputs, parameter.LogItemMetadata); } @@ -1560,8 +1564,9 @@ private void GatherArrayStringAndValueOutputs(bool outputTargetIsItem, string ou ItemGroupLoggingHelper.LogTaskParameter( _taskLoggingContext, TaskParameterMessageKind.TaskOutput, - parameter.Name, - parameter.Name, + parameterName: parameter.Name, + propertyName: outputTargetName, + itemType: null, new object[] { outputString }, parameter.LogItemMetadata); } diff --git a/src/Build/Logging/BinaryLogger/BuildEventArgsReader.cs b/src/Build/Logging/BinaryLogger/BuildEventArgsReader.cs index 7b3fc3a3a05..465e6a22aed 100644 --- a/src/Build/Logging/BinaryLogger/BuildEventArgsReader.cs +++ b/src/Build/Logging/BinaryLogger/BuildEventArgsReader.cs @@ -1023,11 +1023,13 @@ private BuildEventArgs ReadTaskParameterEventArgs() var itemType = ReadDeduplicatedString(); var items = ReadTaskItemList() as IList; var parameterName = ReadDeduplicatedString(); + var propertyName = ReadDeduplicatedString(); var e = ItemGroupLoggingHelper.CreateTaskParameterEventArgs( fields.BuildEventContext, kind, parameterName, + propertyName, itemType, items, logItemMetadata: true, diff --git a/src/Build/Logging/BinaryLogger/BuildEventArgsWriter.cs b/src/Build/Logging/BinaryLogger/BuildEventArgsWriter.cs index fba322dc171..a9a734b1638 100644 --- a/src/Build/Logging/BinaryLogger/BuildEventArgsWriter.cs +++ b/src/Build/Logging/BinaryLogger/BuildEventArgsWriter.cs @@ -572,6 +572,7 @@ private BinaryLogRecordKind Write(TaskParameterEventArgs e) WriteDeduplicatedString(e.ItemType); WriteTaskItemList(e.Items, e.LogItemMetadata); WriteDeduplicatedString(e.ParameterName); + WriteDeduplicatedString(e.PropertyName); if (e.Kind == TaskParameterMessageKind.AddItem || e.Kind == TaskParameterMessageKind.TaskOutput) { diff --git a/src/Build/Resources/Strings.resx b/src/Build/Resources/Strings.resx index 62bcd2464c3..32d308cacbc 100644 --- a/src/Build/Resources/Strings.resx +++ b/src/Build/Resources/Strings.resx @@ -1102,6 +1102,9 @@ Output Item(s): + + Output Property: + Output Property: {0}={1} diff --git a/src/Build/Resources/xlf/Strings.cs.xlf b/src/Build/Resources/xlf/Strings.cs.xlf index cce18578077..01111d770e3 100644 --- a/src/Build/Resources/xlf/Strings.cs.xlf +++ b/src/Build/Resources/xlf/Strings.cs.xlf @@ -393,6 +393,11 @@ Metoda {0} se nedá zavolat s kolekcí, která obsahuje prázdné cílové názvy nebo názvy null. + + Output Property: + Output Property: + + Created an override using task: {0} at {1} Vytvořilo se přepsání pomocí úlohy: {0} v {1} diff --git a/src/Build/Resources/xlf/Strings.de.xlf b/src/Build/Resources/xlf/Strings.de.xlf index d1aa6cbc8ec..d1b394878f2 100644 --- a/src/Build/Resources/xlf/Strings.de.xlf +++ b/src/Build/Resources/xlf/Strings.de.xlf @@ -393,6 +393,11 @@ Die Methode "{0}" kann nicht mit einer Sammlung aufgerufen werden, die NULL oder leere Zielnamen enthält. + + Output Property: + Output Property: + + Created an override using task: {0} at {1} Außerkraftsetzung mit Task erstellt: {0} bei {1} diff --git a/src/Build/Resources/xlf/Strings.es.xlf b/src/Build/Resources/xlf/Strings.es.xlf index 90914c626ff..1fca3294b7c 100644 --- a/src/Build/Resources/xlf/Strings.es.xlf +++ b/src/Build/Resources/xlf/Strings.es.xlf @@ -393,6 +393,11 @@ No se puede llamar al método {0} con una colección que contiene nombres de destino nulos o vacíos. + + Output Property: + Output Property: + + Created an override using task: {0} at {1} Se creó una invalidación mediante la tarea: {0} en {1} diff --git a/src/Build/Resources/xlf/Strings.fr.xlf b/src/Build/Resources/xlf/Strings.fr.xlf index 09bad2f7e80..f5808cbd2be 100644 --- a/src/Build/Resources/xlf/Strings.fr.xlf +++ b/src/Build/Resources/xlf/Strings.fr.xlf @@ -393,6 +393,11 @@ Impossible d'appeler la méthode {0} avec une collection contenant des noms de cibles qui ont une valeur null ou qui sont vides. + + Output Property: + Output Property: + + Created an override using task: {0} at {1} Remplacement créé à l’aide de la tâche : {0} au {1} diff --git a/src/Build/Resources/xlf/Strings.it.xlf b/src/Build/Resources/xlf/Strings.it.xlf index 8bf8eec2d8d..67f13f70d43 100644 --- a/src/Build/Resources/xlf/Strings.it.xlf +++ b/src/Build/Resources/xlf/Strings.it.xlf @@ -393,6 +393,11 @@ Non è possibile chiamare il metodo {0} con una raccolta contenente nomi di destinazione Null o vuoti. + + Output Property: + Output Property: + + Created an override using task: {0} at {1} È stata creata una sostituzione con l'attività: {0} in {1} diff --git a/src/Build/Resources/xlf/Strings.ja.xlf b/src/Build/Resources/xlf/Strings.ja.xlf index fbdc02d0590..c6fe789da0d 100644 --- a/src/Build/Resources/xlf/Strings.ja.xlf +++ b/src/Build/Resources/xlf/Strings.ja.xlf @@ -393,6 +393,11 @@ Null または空のターゲット名を含むコレクションを指定してメソッド {0} を呼び出すことはできません。 + + Output Property: + Output Property: + + Created an override using task: {0} at {1} タスクを使用してオーバーライドを作成しました: {1} の {0} diff --git a/src/Build/Resources/xlf/Strings.ko.xlf b/src/Build/Resources/xlf/Strings.ko.xlf index dc7c94b9d2f..cdac9492ab1 100644 --- a/src/Build/Resources/xlf/Strings.ko.xlf +++ b/src/Build/Resources/xlf/Strings.ko.xlf @@ -393,6 +393,11 @@ null 또는 빈 대상 이름을 포함하는 컬렉션을 사용하여 {0} 메서드를 호출할 수 없습니다. + + Output Property: + Output Property: + + Created an override using task: {0} at {1} 다음 작업을 사용하여 재정의를 만들었습니다. {1}의 {0} diff --git a/src/Build/Resources/xlf/Strings.pl.xlf b/src/Build/Resources/xlf/Strings.pl.xlf index d8d09cb9c63..27befb97cf5 100644 --- a/src/Build/Resources/xlf/Strings.pl.xlf +++ b/src/Build/Resources/xlf/Strings.pl.xlf @@ -393,6 +393,11 @@ Metody {0} nie można wywołać przy użyciu kolekcji zawierającej nazwy docelowe o wartości null lub puste. + + Output Property: + Output Property: + + Created an override using task: {0} at {1} Utworzono zastąpienie przy użyciu zadania: {0} o {1} diff --git a/src/Build/Resources/xlf/Strings.pt-BR.xlf b/src/Build/Resources/xlf/Strings.pt-BR.xlf index 389700299cc..cb83c722ef8 100644 --- a/src/Build/Resources/xlf/Strings.pt-BR.xlf +++ b/src/Build/Resources/xlf/Strings.pt-BR.xlf @@ -393,6 +393,11 @@ O método {0} não pode ser chamado com uma coleção que contém nomes de destino nulos ou vazios. + + Output Property: + Output Property: + + Created an override using task: {0} at {1} Criou uma substituição usando a tarefa: {0} em {1} diff --git a/src/Build/Resources/xlf/Strings.ru.xlf b/src/Build/Resources/xlf/Strings.ru.xlf index 5c04d7194eb..b9d85985c8b 100644 --- a/src/Build/Resources/xlf/Strings.ru.xlf +++ b/src/Build/Resources/xlf/Strings.ru.xlf @@ -393,6 +393,11 @@ Метод {0} не может быть вызван с коллекцией, содержащей целевые имена, которые пусты или равны NULL. + + Output Property: + Output Property: + + Created an override using task: {0} at {1} Создано переопределение с помощью задачи {0} в {1} diff --git a/src/Build/Resources/xlf/Strings.tr.xlf b/src/Build/Resources/xlf/Strings.tr.xlf index a9dc8a0e065..2fe1897b791 100644 --- a/src/Build/Resources/xlf/Strings.tr.xlf +++ b/src/Build/Resources/xlf/Strings.tr.xlf @@ -393,6 +393,11 @@ {0} metosu null veya boş hedef adları içeren bir koleksiyonla çağrılamaz. + + Output Property: + Output Property: + + Created an override using task: {0} at {1} {0} görevi kullanılarak geçersiz kılma işlemi oluşturuldu, saat: {1} diff --git a/src/Build/Resources/xlf/Strings.zh-Hans.xlf b/src/Build/Resources/xlf/Strings.zh-Hans.xlf index 868e495f52b..d4834faab5a 100644 --- a/src/Build/Resources/xlf/Strings.zh-Hans.xlf +++ b/src/Build/Resources/xlf/Strings.zh-Hans.xlf @@ -393,6 +393,11 @@ 无法使用包含 null 或空目标名称的集合调用方法 {0}。 + + Output Property: + Output Property: + + Created an override using task: {0} at {1} 已使用任务创建替代: {0} 位于 {1} diff --git a/src/Build/Resources/xlf/Strings.zh-Hant.xlf b/src/Build/Resources/xlf/Strings.zh-Hant.xlf index b31a9ad4517..3735847ae07 100644 --- a/src/Build/Resources/xlf/Strings.zh-Hant.xlf +++ b/src/Build/Resources/xlf/Strings.zh-Hant.xlf @@ -393,6 +393,11 @@ 無法使用內含 null 或空白目標名稱的集合呼叫方法 {0}。 + + Output Property: + Output Property: + + Created an override using task: {0} at {1} 已使用下列工作建立覆寫: 於 {1} 的 {0} diff --git a/src/Framework/TaskParameterEventArgs.cs b/src/Framework/TaskParameterEventArgs.cs index 04fb6a8aec1..d9ad4c0d4bd 100644 --- a/src/Framework/TaskParameterEventArgs.cs +++ b/src/Framework/TaskParameterEventArgs.cs @@ -35,6 +35,7 @@ public class TaskParameterEventArgs : BuildMessageEventArgs public TaskParameterEventArgs( TaskParameterMessageKind kind, string parameterName, + string propertyName, string itemType, IList items, bool logItemMetadata, @@ -43,6 +44,7 @@ public TaskParameterEventArgs( { Kind = kind; ParameterName = parameterName; + PropertyName = propertyName; ItemType = itemType; Items = items; LogItemMetadata = logItemMetadata; @@ -57,7 +59,7 @@ public TaskParameterEventArgs( IList items, bool logItemMetadata, DateTime eventTimestamp) - : this(kind, parameterName: null, itemType, items, logItemMetadata, eventTimestamp) + : this(kind, parameterName: null, propertyName: null, itemType, items, logItemMetadata, eventTimestamp) { } /// @@ -66,14 +68,20 @@ public TaskParameterEventArgs( public TaskParameterMessageKind Kind { get; private set; } /// - /// The name of the parameter if is or . + /// The name of the parameter if is or , + /// null otherwise. /// public string ParameterName { get; private set; } /// - /// The name of the item being manipulated, e.g. "Compile". For backward compatibility, this property has the same value - /// as in cases where the operation does not manipulate any items, such as when representing - /// task inputs or task outputs assigned to properties. + /// The name of the property if is and the task output + /// is assigned to a property, null otherwise. + /// + public string PropertyName { get; private set; } + + /// + /// The name of the item being manipulated, e.g. "Compile", or null in cases where the operation does not manipulate + /// any items, such as when representing task inputs or task outputs assigned to properties. /// public string ItemType { get; private set; } @@ -122,6 +130,7 @@ internal override void CreateFromStream(BinaryReader reader, int version) BuildEventContext = reader.ReadOptionalBuildEventContext(); Kind = (TaskParameterMessageKind)reader.Read7BitEncodedInt(); ParameterName = reader.ReadOptionalString(); + PropertyName = reader.ReadOptionalString(); ItemType = reader.ReadOptionalString(); LineNumber = reader.Read7BitEncodedInt(); ColumnNumber = reader.Read7BitEncodedInt(); @@ -172,6 +181,7 @@ internal override void WriteToStream(BinaryWriter writer) writer.WriteOptionalBuildEventContext(BuildEventContext); writer.Write7BitEncodedInt((int)Kind); writer.WriteOptionalString(ParameterName); + writer.WriteOptionalString(PropertyName); writer.WriteOptionalString(ItemType); writer.Write7BitEncodedInt(LineNumber); writer.Write7BitEncodedInt(ColumnNumber); From 88b29b6803426141976447e0d309970e8155140e Mon Sep 17 00:00:00 2001 From: Ladi Prosek Date: Wed, 15 May 2024 13:01:03 +0200 Subject: [PATCH 6/9] Check binlog version when reading parameter name and property name --- src/Build/Logging/BinaryLogger/BuildEventArgsReader.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Build/Logging/BinaryLogger/BuildEventArgsReader.cs b/src/Build/Logging/BinaryLogger/BuildEventArgsReader.cs index 465e6a22aed..358c410265f 100644 --- a/src/Build/Logging/BinaryLogger/BuildEventArgsReader.cs +++ b/src/Build/Logging/BinaryLogger/BuildEventArgsReader.cs @@ -1022,8 +1022,9 @@ private BuildEventArgs ReadTaskParameterEventArgs() var kind = (TaskParameterMessageKind)ReadInt32(); var itemType = ReadDeduplicatedString(); var items = ReadTaskItemList() as IList; - var parameterName = ReadDeduplicatedString(); - var propertyName = ReadDeduplicatedString(); + var (parameterName, propertyName) = _fileFormatVersion >= 21 + ? (ReadDeduplicatedString(), ReadDeduplicatedString()) + : (null, null); var e = ItemGroupLoggingHelper.CreateTaskParameterEventArgs( fields.BuildEventContext, From 3109e71ea12b6629907e011479e0dea39f7a0ce8 Mon Sep 17 00:00:00 2001 From: Ladi Prosek Date: Thu, 16 May 2024 09:09:23 +0200 Subject: [PATCH 7/9] Update comment --- src/Build/Logging/BinaryLogger/BinaryLogger.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Build/Logging/BinaryLogger/BinaryLogger.cs b/src/Build/Logging/BinaryLogger/BinaryLogger.cs index 99887549606..d4c37461938 100644 --- a/src/Build/Logging/BinaryLogger/BinaryLogger.cs +++ b/src/Build/Logging/BinaryLogger/BinaryLogger.cs @@ -72,7 +72,7 @@ public sealed class BinaryLogger : ILogger // version 20: // - TaskStartedEventArgs: Added TaskAssemblyLocation property // version 21: - // - TaskParameterEventArgs: Added ParameterName property + // - TaskParameterEventArgs: Added ParameterName and PropertyName properties // This should be never changed. // The minimum version of the binary log reader that can read log of above version. From bfde92902d704843bf7f2af55c60407128d03bee Mon Sep 17 00:00:00 2001 From: Ladi Prosek Date: Fri, 17 May 2024 17:59:26 +0200 Subject: [PATCH 8/9] Update src/Build.UnitTests/BuildEventArgsSerialization_Tests.cs Co-authored-by: Rainer Sigwald --- src/Build.UnitTests/BuildEventArgsSerialization_Tests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Build.UnitTests/BuildEventArgsSerialization_Tests.cs b/src/Build.UnitTests/BuildEventArgsSerialization_Tests.cs index c391c4cd87a..bd03a54d29a 100644 --- a/src/Build.UnitTests/BuildEventArgsSerialization_Tests.cs +++ b/src/Build.UnitTests/BuildEventArgsSerialization_Tests.cs @@ -650,7 +650,7 @@ public void RoundtripTaskParameterEventArgs() new TaskItemData("ItemSpec1", null), new TaskItemData("ItemSpec2", Enumerable.Range(1,3).ToDictionary(i => i.ToString(), i => i.ToString() + "value")) }; - var args = new TaskParameterEventArgs(TaskParameterMessageKind.TaskOutput, "ParameterName", "PropertyName", "ItemName", items, true, DateTime.MinValue); + var args = new TaskParameterEventArgs(TaskParameterMessageKind.TaskOutput, "ParameterName1", "PropertyName1", "ItemName1", items, true, DateTime.MinValue); args.LineNumber = 265; args.ColumnNumber = 6; From 650f7df6176f0c591f7e63b75731de4ef2fdef17 Mon Sep 17 00:00:00 2001 From: Ladi Prosek Date: Wed, 22 May 2024 14:34:10 +0200 Subject: [PATCH 9/9] Make TaskParameterEventArgs backward compatible --- .../BackEnd/TaskExecutionHost/TaskExecutionHost.cs | 10 ++++++++-- src/Framework/TaskParameterEventArgs.cs | 5 +++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs b/src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs index bacc0ad5914..c1b49647f8e 100644 --- a/src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs +++ b/src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs @@ -1317,6 +1317,8 @@ private bool InternalSetTaskParameter( // Structured logging for all parameters that have logging enabled and are not empty lists. if (parameterValueAsList?.Count > 0 || (parameterValueAsList == null && !legacyBehavior)) { + // Note: We're setting TaskParameterEventArgs.ItemType to parameter name for backward compatibility with + // older loggers and binlog viewers. ItemGroupLoggingHelper.LogTaskParameter( _taskLoggingContext, TaskParameterMessageKind.TaskInput, @@ -1476,12 +1478,14 @@ static IEnumerable> EnumerateMetadata(IDictionary c { if (ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_12)) { + // Note: We're setting TaskParameterEventArgs.ItemType to property name for backward compatibility with + // older loggers and binlog viewers. ItemGroupLoggingHelper.LogTaskParameter( _taskLoggingContext, TaskParameterMessageKind.TaskOutput, parameterName: parameter.Name, propertyName: outputTargetName, - itemType: null, + itemType: outputTargetName, new object[] { outputString }, parameter.LogItemMetadata); } @@ -1561,12 +1565,14 @@ private void GatherArrayStringAndValueOutputs(bool outputTargetIsItem, string ou { if (ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_12)) { + // Note: We're setting TaskParameterEventArgs.ItemType to property name for backward compatibility with + // older loggers and binlog viewers. ItemGroupLoggingHelper.LogTaskParameter( _taskLoggingContext, TaskParameterMessageKind.TaskOutput, parameterName: parameter.Name, propertyName: outputTargetName, - itemType: null, + itemType: outputTargetName, new object[] { outputString }, parameter.LogItemMetadata); } diff --git a/src/Framework/TaskParameterEventArgs.cs b/src/Framework/TaskParameterEventArgs.cs index d9ad4c0d4bd..8dcf97730c7 100644 --- a/src/Framework/TaskParameterEventArgs.cs +++ b/src/Framework/TaskParameterEventArgs.cs @@ -80,8 +80,9 @@ public TaskParameterEventArgs( public string PropertyName { get; private set; } /// - /// The name of the item being manipulated, e.g. "Compile", or null in cases where the operation does not manipulate - /// any items, such as when representing task inputs or task outputs assigned to properties. + /// The name of the item being manipulated, e.g. "Compile" if this is an item operation. If this object represents a task input, this property should be set + /// to the same value as for backward compatibility. Similarly, if this object represents a task output assigned to a property, + /// this should be set to the same value as for backward compatibility. /// public string ItemType { get; private set; }