ILoggingService loggingServices,
BuildEventContext buildEventContext,
IFileSystem fileSystem,
- ProjectRootElementCacheBase projectRootElementCache = null
+ ProjectRootElementCacheBase projectRootElementCache = null,
+ LoggingContext loggingContext = null
)
where P : class, IProperty
where I : class, IItem
@@ -279,7 +283,7 @@ internal static bool EvaluateConditionCollectingConditionedProperties
{
try
{
- result = parsedExpression.Evaluate(state);
+ result = parsedExpression.Evaluate(state, loggingContext);
}
finally
{
@@ -353,7 +357,7 @@ internal interface IConditionEvaluationState
/// May return null if the expression would expand to non-empty and it broke out early.
/// Otherwise, returns the correctly expanded expression.
///
- string ExpandIntoStringBreakEarly(string expression);
+ string ExpandIntoStringBreakEarly(string expression, LoggingContext loggingContext = null);
///
/// Expands the specified expression into a list of TaskItem's.
@@ -363,7 +367,7 @@ internal interface IConditionEvaluationState
///
/// Expands the specified expression into a string.
///
- string ExpandIntoString(string expression);
+ string ExpandIntoString(string expression, LoggingContext loggingContext = null);
///
/// PRE cache
@@ -440,11 +444,11 @@ internal ConditionEvaluationState
/// May return null if the expression would expand to non-empty and it broke out early.
/// Otherwise, returns the correctly expanded expression.
///
- public string ExpandIntoStringBreakEarly(string expression)
+ public string ExpandIntoStringBreakEarly(string expression, LoggingContext loggingContext = null)
{
var originalValue = _expander.WarnForUninitializedProperties;
- expression = _expander.ExpandIntoStringAndUnescape(expression, _expanderOptions | ExpanderOptions.BreakOnNotEmpty, ElementLocation);
+ expression = _expander.ExpandIntoStringAndUnescape(expression, _expanderOptions | ExpanderOptions.BreakOnNotEmpty, ElementLocation, loggingContext);
_expander.WarnForUninitializedProperties = originalValue;
@@ -471,12 +475,13 @@ public IList ExpandIntoTaskItems(string expression)
/// Expands the specified expression into a string.
///
/// The expression to expand.
+ ///
/// The expanded string.
- public string ExpandIntoString(string expression)
+ public string ExpandIntoString(string expression, LoggingContext loggingContext = null)
{
var originalValue = _expander.WarnForUninitializedProperties;
- expression = _expander.ExpandIntoStringAndUnescape(expression, _expanderOptions, ElementLocation);
+ expression = _expander.ExpandIntoStringAndUnescape(expression, _expanderOptions, ElementLocation, loggingContext);
_expander.WarnForUninitializedProperties = originalValue;
diff --git a/src/Build/Evaluation/Conditionals/AndExpressionNode.cs b/src/Build/Evaluation/Conditionals/AndExpressionNode.cs
index 94513436e9c..47481c625c3 100644
--- a/src/Build/Evaluation/Conditionals/AndExpressionNode.cs
+++ b/src/Build/Evaluation/Conditionals/AndExpressionNode.cs
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+using Microsoft.Build.BackEnd.Logging;
using Microsoft.Build.Shared;
using System.Diagnostics;
@@ -18,9 +19,9 @@ internal sealed class AndExpressionNode : OperatorExpressionNode
///
/// Evaluate as boolean
///
- internal override bool BoolEvaluate(ConditionEvaluator.IConditionEvaluationState state)
+ internal override bool BoolEvaluate(ConditionEvaluator.IConditionEvaluationState state, LoggingContext loggingContext = null)
{
- if (!LeftChild.TryBoolEvaluate(state, out bool leftBool))
+ if (!LeftChild.TryBoolEvaluate(state, out bool leftBool, loggingContext))
{
ProjectErrorUtilities.ThrowInvalidProject(
state.ElementLocation,
@@ -37,7 +38,7 @@ internal override bool BoolEvaluate(ConditionEvaluator.IConditionEvaluationState
}
else
{
- if (!RightChild.TryBoolEvaluate(state, out bool rightBool))
+ if (!RightChild.TryBoolEvaluate(state, out bool rightBool, loggingContext))
{
ProjectErrorUtilities.ThrowInvalidProject(
state.ElementLocation,
diff --git a/src/Build/Evaluation/Conditionals/FunctionCallExpressionNode.cs b/src/Build/Evaluation/Conditionals/FunctionCallExpressionNode.cs
index e0b57181361..4ec222243fd 100644
--- a/src/Build/Evaluation/Conditionals/FunctionCallExpressionNode.cs
+++ b/src/Build/Evaluation/Conditionals/FunctionCallExpressionNode.cs
@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.IO;
+using Microsoft.Build.BackEnd.Logging;
using Microsoft.Build.Shared;
using TaskItem = Microsoft.Build.Execution.ProjectItemInstance.TaskItem;
@@ -29,7 +30,7 @@ internal FunctionCallExpressionNode(string functionName, List
/// Evaluate node as boolean
///
- internal override bool BoolEvaluate(ConditionEvaluator.IConditionEvaluationState state)
+ internal override bool BoolEvaluate(ConditionEvaluator.IConditionEvaluationState state, LoggingContext loggingContext = null)
{
if (String.Equals(_functionName, "exists", StringComparison.OrdinalIgnoreCase))
{
diff --git a/src/Build/Evaluation/Conditionals/GenericExpressionNode.cs b/src/Build/Evaluation/Conditionals/GenericExpressionNode.cs
index d6007133404..50efb172cf7 100644
--- a/src/Build/Evaluation/Conditionals/GenericExpressionNode.cs
+++ b/src/Build/Evaluation/Conditionals/GenericExpressionNode.cs
@@ -2,7 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
-
+using Microsoft.Build.BackEnd.Logging;
using Microsoft.Build.Shared;
#nullable disable
@@ -14,9 +14,9 @@ namespace Microsoft.Build.Evaluation
///
internal abstract class GenericExpressionNode
{
- internal abstract bool TryBoolEvaluate(ConditionEvaluator.IConditionEvaluationState state, out bool result);
- internal abstract bool TryNumericEvaluate(ConditionEvaluator.IConditionEvaluationState state, out double result);
- internal abstract bool TryVersionEvaluate(ConditionEvaluator.IConditionEvaluationState state, out Version result);
+ internal abstract bool TryBoolEvaluate(ConditionEvaluator.IConditionEvaluationState state, out bool result, LoggingContext loggingContext = null);
+ internal abstract bool TryNumericEvaluate(ConditionEvaluator.IConditionEvaluationState state, out double result, LoggingContext loggingContext = null);
+ internal abstract bool TryVersionEvaluate(ConditionEvaluator.IConditionEvaluationState state, out Version result, LoggingContext loggingContext = null);
///
/// Returns true if this node evaluates to an empty string,
@@ -25,7 +25,7 @@ internal abstract class GenericExpressionNode
/// to empty than to fully evaluate it.)
/// Implementations should cache the result so that calls after the first are free.
///
- internal virtual bool EvaluatesToEmpty(ConditionEvaluator.IConditionEvaluationState state)
+ internal virtual bool EvaluatesToEmpty(ConditionEvaluator.IConditionEvaluationState state, LoggingContext loggingContext = null)
{
return false;
}
@@ -34,7 +34,7 @@ internal virtual bool EvaluatesToEmpty(ConditionEvaluator.IConditionEvaluationSt
/// Value after any item and property expressions are expanded
///
///
- internal abstract string GetExpandedValue(ConditionEvaluator.IConditionEvaluationState state);
+ internal abstract string GetExpandedValue(ConditionEvaluator.IConditionEvaluationState state, LoggingContext loggingContext = null);
///
/// Value before any item and property expressions are expanded
@@ -52,16 +52,17 @@ internal virtual bool EvaluatesToEmpty(ConditionEvaluator.IConditionEvaluationSt
/// The main evaluate entry point for expression trees
///
///
+ ///
///
- internal bool Evaluate(ConditionEvaluator.IConditionEvaluationState state)
+ internal bool Evaluate(ConditionEvaluator.IConditionEvaluationState state, LoggingContext loggingContext = null)
{
- if (!TryBoolEvaluate(state, out bool boolValue))
+ if (!TryBoolEvaluate(state, out bool boolValue, loggingContext))
{
ProjectErrorUtilities.ThrowInvalidProject(
state.ElementLocation,
"ConditionNotBooleanDetail",
state.Condition,
- GetExpandedValue(state));
+ GetExpandedValue(state, loggingContext));
}
return boolValue;
diff --git a/src/Build/Evaluation/Conditionals/MultipleComparisonExpressionNode.cs b/src/Build/Evaluation/Conditionals/MultipleComparisonExpressionNode.cs
index 65e23c7718f..1ef13748bdc 100644
--- a/src/Build/Evaluation/Conditionals/MultipleComparisonExpressionNode.cs
+++ b/src/Build/Evaluation/Conditionals/MultipleComparisonExpressionNode.cs
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+using Microsoft.Build.BackEnd.Logging;
using Microsoft.Build.Shared;
#nullable disable
@@ -36,7 +37,7 @@ internal abstract class MultipleComparisonNode : OperatorExpressionNode
/// Order in which comparisons are attempted is numeric, boolean, then string.
/// Updates conditioned properties table.
///
- internal override bool BoolEvaluate(ConditionEvaluator.IConditionEvaluationState state)
+ internal override bool BoolEvaluate(ConditionEvaluator.IConditionEvaluationState state, LoggingContext loggingContext)
{
ProjectErrorUtilities.VerifyThrowInvalidProject
(LeftChild != null && RightChild != null,
@@ -50,8 +51,8 @@ internal override bool BoolEvaluate(ConditionEvaluator.IConditionEvaluationState
// and we know which do, then we already have enough information to evaluate this expression.
// That means we don't have to fully expand a condition like " '@(X)' == '' "
// which is a performance advantage if @(X) is a huge item list.
- bool leftEmpty = LeftChild.EvaluatesToEmpty(state);
- bool rightEmpty = RightChild.EvaluatesToEmpty(state);
+ bool leftEmpty = LeftChild.EvaluatesToEmpty(state, loggingContext);
+ bool rightEmpty = RightChild.EvaluatesToEmpty(state, loggingContext);
if (leftEmpty || rightEmpty)
{
UpdateConditionedProperties(state);
@@ -68,13 +69,13 @@ internal override bool BoolEvaluate(ConditionEvaluator.IConditionEvaluationState
// is 17.0).
return Compare(leftNumericValue, rightNumericValue);
}
- else if (LeftChild.TryBoolEvaluate(state, out bool leftBoolValue) && RightChild.TryBoolEvaluate(state, out bool rightBoolValue))
+ else if (LeftChild.TryBoolEvaluate(state, out bool leftBoolValue, loggingContext) && RightChild.TryBoolEvaluate(state, out bool rightBoolValue, loggingContext))
{
return Compare(leftBoolValue, rightBoolValue);
}
- string leftExpandedValue = LeftChild.GetExpandedValue(state);
- string rightExpandedValue = RightChild.GetExpandedValue(state);
+ string leftExpandedValue = LeftChild.GetExpandedValue(state, loggingContext);
+ string rightExpandedValue = RightChild.GetExpandedValue(state, loggingContext);
ProjectErrorUtilities.VerifyThrowInvalidProject
(leftExpandedValue != null && rightExpandedValue != null,
diff --git a/src/Build/Evaluation/Conditionals/NotExpressionNode.cs b/src/Build/Evaluation/Conditionals/NotExpressionNode.cs
index e5b00ac781a..1d2e1d6311e 100644
--- a/src/Build/Evaluation/Conditionals/NotExpressionNode.cs
+++ b/src/Build/Evaluation/Conditionals/NotExpressionNode.cs
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+using Microsoft.Build.BackEnd.Logging;
using Microsoft.Build.Shared;
using System.Diagnostics;
@@ -18,9 +19,9 @@ internal sealed class NotExpressionNode : OperatorExpressionNode
///
/// Evaluate as boolean
///
- internal override bool BoolEvaluate(ConditionEvaluator.IConditionEvaluationState state)
+ internal override bool BoolEvaluate(ConditionEvaluator.IConditionEvaluationState state, LoggingContext loggingContext = null)
{
- if (!LeftChild.TryBoolEvaluate(state, out bool boolValue))
+ if (!LeftChild.TryBoolEvaluate(state, out bool boolValue, loggingContext))
{
ProjectErrorUtilities.ThrowInvalidProject(
state.ElementLocation,
@@ -44,9 +45,9 @@ internal override string GetUnexpandedValue(ConditionEvaluator.IConditionEvaluat
///
/// Returns expanded value with '!' prepended. Useful for error messages.
///
- internal override string GetExpandedValue(ConditionEvaluator.IConditionEvaluationState state)
+ internal override string GetExpandedValue(ConditionEvaluator.IConditionEvaluationState state, LoggingContext loggingContext = null)
{
- return "!" + LeftChild.GetExpandedValue(state);
+ return "!" + LeftChild.GetExpandedValue(state, loggingContext);
}
internal override string DebuggerDisplay => $"(not {LeftChild.DebuggerDisplay})";
diff --git a/src/Build/Evaluation/Conditionals/NumericComparisonExpressionNode.cs b/src/Build/Evaluation/Conditionals/NumericComparisonExpressionNode.cs
index 02c242ceef5..f161ad5d18b 100644
--- a/src/Build/Evaluation/Conditionals/NumericComparisonExpressionNode.cs
+++ b/src/Build/Evaluation/Conditionals/NumericComparisonExpressionNode.cs
@@ -2,7 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
-
+using Microsoft.Build.BackEnd.Logging;
using Microsoft.Build.Shared;
#nullable disable
@@ -38,7 +38,7 @@ internal abstract class NumericComparisonExpressionNode : OperatorExpressionNode
///
/// Evaluate as boolean
///
- internal override bool BoolEvaluate(ConditionEvaluator.IConditionEvaluationState state)
+ internal override bool BoolEvaluate(ConditionEvaluator.IConditionEvaluationState state, LoggingContext loggingContext = null)
{
bool isLeftNum = LeftChild.TryNumericEvaluate(state, out double leftNum);
bool isLeftVersion = LeftChild.TryVersionEvaluate(state, out Version leftVersion);
@@ -53,7 +53,7 @@ internal override bool BoolEvaluate(ConditionEvaluator.IConditionEvaluationState
state.Condition,
/* helpfully display unexpanded token and expanded result in error message */
isLeftNum ? RightChild.GetUnexpandedValue(state) : LeftChild.GetUnexpandedValue(state),
- isLeftNum ? RightChild.GetExpandedValue(state) : LeftChild.GetExpandedValue(state));
+ isLeftNum ? RightChild.GetExpandedValue(state, loggingContext) : LeftChild.GetExpandedValue(state, loggingContext));
}
return (isLeftNum, isLeftVersion, isRightNum, isRightVersion) switch
diff --git a/src/Build/Evaluation/Conditionals/NumericExpressionNode.cs b/src/Build/Evaluation/Conditionals/NumericExpressionNode.cs
index 66fa552443d..7725d9962dc 100644
--- a/src/Build/Evaluation/Conditionals/NumericExpressionNode.cs
+++ b/src/Build/Evaluation/Conditionals/NumericExpressionNode.cs
@@ -3,7 +3,7 @@
using System;
using System.Diagnostics;
-
+using Microsoft.Build.BackEnd.Logging;
using Microsoft.Build.Shared;
#nullable disable
@@ -23,18 +23,18 @@ internal NumericExpressionNode(string value)
_value = value;
}
- internal override bool TryBoolEvaluate(ConditionEvaluator.IConditionEvaluationState state, out bool result)
+ internal override bool TryBoolEvaluate(ConditionEvaluator.IConditionEvaluationState state, out bool result, LoggingContext loggingContext = null)
{
result = default;
return false;
}
- internal override bool TryNumericEvaluate(ConditionEvaluator.IConditionEvaluationState state, out double result)
+ internal override bool TryNumericEvaluate(ConditionEvaluator.IConditionEvaluationState state, out double result, LoggingContext loggingContext = null)
{
return ConversionUtilities.TryConvertDecimalOrHexToDouble(_value, out result);
}
- internal override bool TryVersionEvaluate(ConditionEvaluator.IConditionEvaluationState state, out Version result)
+ internal override bool TryVersionEvaluate(ConditionEvaluator.IConditionEvaluationState state, out Version result, LoggingContext loggingContext = null)
{
return Version.TryParse(_value, out result);
}
@@ -50,7 +50,7 @@ internal override string GetUnexpandedValue(ConditionEvaluator.IConditionEvaluat
///
/// Get the expanded value
///
- internal override string GetExpandedValue(ConditionEvaluator.IConditionEvaluationState state)
+ internal override string GetExpandedValue(ConditionEvaluator.IConditionEvaluationState state, LoggingContext loggingContext = null)
{
return _value;
}
diff --git a/src/Build/Evaluation/Conditionals/OperatorExpressionNode.cs b/src/Build/Evaluation/Conditionals/OperatorExpressionNode.cs
index c6e4b4c349c..a3f76ff20ff 100644
--- a/src/Build/Evaluation/Conditionals/OperatorExpressionNode.cs
+++ b/src/Build/Evaluation/Conditionals/OperatorExpressionNode.cs
@@ -2,6 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
+using Microsoft.Build.BackEnd.Logging;
#nullable disable
@@ -12,21 +13,21 @@ namespace Microsoft.Build.Evaluation
///
internal abstract class OperatorExpressionNode : GenericExpressionNode
{
- internal override bool TryBoolEvaluate(ConditionEvaluator.IConditionEvaluationState state, out bool result)
+ internal override bool TryBoolEvaluate(ConditionEvaluator.IConditionEvaluationState state, out bool result, LoggingContext loggingContext = null)
{
- result = BoolEvaluate(state);
+ result = BoolEvaluate(state, loggingContext);
return true;
}
- internal abstract bool BoolEvaluate(ConditionEvaluator.IConditionEvaluationState state);
+ internal abstract bool BoolEvaluate(ConditionEvaluator.IConditionEvaluationState state, LoggingContext loggingContext = null);
- internal override bool TryNumericEvaluate(ConditionEvaluator.IConditionEvaluationState state, out double result)
+ internal override bool TryNumericEvaluate(ConditionEvaluator.IConditionEvaluationState state, out double result, LoggingContext loggingContext = null)
{
result = default;
return false;
}
- internal override bool TryVersionEvaluate(ConditionEvaluator.IConditionEvaluationState state, out Version result)
+ internal override bool TryVersionEvaluate(ConditionEvaluator.IConditionEvaluationState state, out Version result, LoggingContext loggingContext = null)
{
result = default;
return false;
@@ -36,7 +37,7 @@ internal override bool TryVersionEvaluate(ConditionEvaluator.IConditionEvaluatio
/// Value after any item and property expressions are expanded
///
///
- internal override string GetExpandedValue(ConditionEvaluator.IConditionEvaluationState state)
+ internal override string GetExpandedValue(ConditionEvaluator.IConditionEvaluationState state, LoggingContext loggingContext = null)
{
return null;
}
diff --git a/src/Build/Evaluation/Conditionals/OrExpressionNode.cs b/src/Build/Evaluation/Conditionals/OrExpressionNode.cs
index 250e8c9602c..fa1816c2e1d 100644
--- a/src/Build/Evaluation/Conditionals/OrExpressionNode.cs
+++ b/src/Build/Evaluation/Conditionals/OrExpressionNode.cs
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+using Microsoft.Build.BackEnd.Logging;
using Microsoft.Build.Shared;
using System.Diagnostics;
@@ -18,15 +19,15 @@ internal sealed class OrExpressionNode : OperatorExpressionNode
///
/// Evaluate as boolean
///
- internal override bool BoolEvaluate(ConditionEvaluator.IConditionEvaluationState state)
+ internal override bool BoolEvaluate(ConditionEvaluator.IConditionEvaluationState state, LoggingContext loggingContext = null)
{
- if (!LeftChild.TryBoolEvaluate(state, out bool leftBool))
+ if (!LeftChild.TryBoolEvaluate(state, out bool leftBool, loggingContext))
{
ProjectErrorUtilities.ThrowInvalidProject(
state.ElementLocation,
"ExpressionDoesNotEvaluateToBoolean",
LeftChild.GetUnexpandedValue(state),
- LeftChild.GetExpandedValue(state),
+ LeftChild.GetExpandedValue(state, loggingContext),
state.Condition);
}
@@ -37,7 +38,7 @@ internal override bool BoolEvaluate(ConditionEvaluator.IConditionEvaluationState
}
else
{
- if (!RightChild.TryBoolEvaluate(state, out bool rightBool))
+ if (!RightChild.TryBoolEvaluate(state, out bool rightBool, loggingContext))
{
ProjectErrorUtilities.ThrowInvalidProject(
state.ElementLocation,
diff --git a/src/Build/Evaluation/Conditionals/StringExpressionNode.cs b/src/Build/Evaluation/Conditionals/StringExpressionNode.cs
index 7017b0b5023..43dd324e7a8 100644
--- a/src/Build/Evaluation/Conditionals/StringExpressionNode.cs
+++ b/src/Build/Evaluation/Conditionals/StringExpressionNode.cs
@@ -3,6 +3,7 @@
using System;
using System.Diagnostics;
+using Microsoft.Build.BackEnd.Logging;
using Microsoft.Build.Shared;
#nullable disable
@@ -30,34 +31,34 @@ internal StringExpressionNode(string value, bool expandable)
_expandable = expandable;
}
- internal override bool TryBoolEvaluate(ConditionEvaluator.IConditionEvaluationState state, out bool result)
+ internal override bool TryBoolEvaluate(ConditionEvaluator.IConditionEvaluationState state, out bool result, LoggingContext loggingContext = null)
{
- return ConversionUtilities.TryConvertStringToBool(GetExpandedValue(state), out result);
+ return ConversionUtilities.TryConvertStringToBool(GetExpandedValue(state, loggingContext), out result);
}
- internal override bool TryNumericEvaluate(ConditionEvaluator.IConditionEvaluationState state, out double result)
+ internal override bool TryNumericEvaluate(ConditionEvaluator.IConditionEvaluationState state, out double result, LoggingContext loggingContext = null)
{
- if (ShouldBeTreatedAsVisualStudioVersion(state))
+ if (ShouldBeTreatedAsVisualStudioVersion(state, loggingContext))
{
result = ConversionUtilities.ConvertDecimalOrHexToDouble(MSBuildConstants.CurrentVisualStudioVersion);
return true;
}
else
{
- return ConversionUtilities.TryConvertDecimalOrHexToDouble(GetExpandedValue(state), out result);
+ return ConversionUtilities.TryConvertDecimalOrHexToDouble(GetExpandedValue(state, loggingContext), out result);
}
}
- internal override bool TryVersionEvaluate(ConditionEvaluator.IConditionEvaluationState state, out Version result)
+ internal override bool TryVersionEvaluate(ConditionEvaluator.IConditionEvaluationState state, out Version result, LoggingContext loggingContext = null)
{
- if (ShouldBeTreatedAsVisualStudioVersion(state))
+ if (ShouldBeTreatedAsVisualStudioVersion(state, loggingContext))
{
result = Version.Parse(MSBuildConstants.CurrentVisualStudioVersion);
return true;
}
else
{
- return Version.TryParse(GetExpandedValue(state), out result);
+ return Version.TryParse(GetExpandedValue(state, loggingContext), out result);
}
}
@@ -68,7 +69,7 @@ internal override bool TryVersionEvaluate(ConditionEvaluator.IConditionEvaluatio
/// to empty than to fully evaluate it.
/// Implementations should cache the result so that calls after the first are free.
///
- internal override bool EvaluatesToEmpty(ConditionEvaluator.IConditionEvaluationState state)
+ internal override bool EvaluatesToEmpty(ConditionEvaluator.IConditionEvaluationState state, LoggingContext loggingContext = null)
{
if (_cachedExpandedValue == null)
{
@@ -93,7 +94,7 @@ internal override bool EvaluatesToEmpty(ConditionEvaluator.IConditionEvaluationS
break;
}
- string expandBreakEarly = state.ExpandIntoStringBreakEarly(_value);
+ string expandBreakEarly = state.ExpandIntoStringBreakEarly(_value, loggingContext);
if (expandBreakEarly == null)
{
@@ -129,13 +130,13 @@ internal override string GetUnexpandedValue(ConditionEvaluator.IConditionEvaluat
/// Value after any item and property expressions are expanded
///
///
- internal override string GetExpandedValue(ConditionEvaluator.IConditionEvaluationState state)
+ internal override string GetExpandedValue(ConditionEvaluator.IConditionEvaluationState state, LoggingContext loggingContext = null)
{
if (_cachedExpandedValue == null)
{
if (_expandable)
{
- _cachedExpandedValue = state.ExpandIntoString(_value);
+ _cachedExpandedValue = state.ExpandIntoString(_value, loggingContext);
}
else
{
@@ -168,7 +169,7 @@ internal override void ResetState()
/// but now cause the project to throw InvalidProjectException when
/// ToolsVersion is "Current". https://github.com/dotnet/msbuild/issues/4150
///
- private bool ShouldBeTreatedAsVisualStudioVersion(ConditionEvaluator.IConditionEvaluationState state)
+ private bool ShouldBeTreatedAsVisualStudioVersion(ConditionEvaluator.IConditionEvaluationState state, LoggingContext loggingContext = null)
{
if (!_shouldBeTreatedAsVisualStudioVersion.HasValue)
{
@@ -176,7 +177,7 @@ private bool ShouldBeTreatedAsVisualStudioVersion(ConditionEvaluator.IConditionE
// Do this check first, because if it's not (common) we can early-out and the next
// expansion will be cheap because this will populate the cached expanded value.
- if (string.Equals(GetExpandedValue(state), MSBuildConstants.CurrentToolsVersion, StringComparison.Ordinal))
+ if (string.Equals(GetExpandedValue(state, loggingContext), MSBuildConstants.CurrentToolsVersion, StringComparison.Ordinal))
{
// and it is just an expansion of MSBuildToolsVersion
_shouldBeTreatedAsVisualStudioVersion = string.Equals(_value, "$(MSBuildToolsVersion)", StringComparison.OrdinalIgnoreCase);
diff --git a/src/Build/Evaluation/Evaluator.cs b/src/Build/Evaluation/Evaluator.cs
index b3154221e9f..ebce24983ad 100644
--- a/src/Build/Evaluation/Evaluator.cs
+++ b/src/Build/Evaluation/Evaluator.cs
@@ -4,7 +4,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
-using ObjectModel = System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
@@ -25,13 +24,15 @@
using Microsoft.Build.Internal;
using Microsoft.Build.Shared;
using Microsoft.Build.Shared.FileSystem;
-using ILoggingService = Microsoft.Build.BackEnd.Logging.ILoggingService;
-using SdkResult = Microsoft.Build.BackEnd.SdkResolution.SdkResult;
-using InvalidProjectFileException = Microsoft.Build.Exceptions.InvalidProjectFileException;
+using static Microsoft.Build.Execution.ProjectPropertyInstance;
using Constants = Microsoft.Build.Internal.Constants;
using EngineFileUtilities = Microsoft.Build.Internal.EngineFileUtilities;
+using ILoggingService = Microsoft.Build.BackEnd.Logging.ILoggingService;
+using InvalidProjectFileException = Microsoft.Build.Exceptions.InvalidProjectFileException;
+using ObjectModel = System.Collections.ObjectModel;
using ReservedPropertyNames = Microsoft.Build.Internal.ReservedPropertyNames;
using SdkReferencePropertyExpansionMode = Microsoft.Build.Framework.EscapeHatches.SdkReferencePropertyExpansionMode;
+using SdkResult = Microsoft.Build.BackEnd.SdkResolution.SdkResult;
#nullable disable
@@ -811,13 +812,30 @@ private void Evaluate()
if (this._evaluationLoggingContext.LoggingService.IncludeEvaluationPropertiesAndItems)
{
globalProperties = _data.GlobalPropertiesDictionary;
- properties = _data.Properties;
+ properties = Traits.Instance.LogAllEnvironmentVariables ? _data.Properties : FilterOutEnvironmentDerivedProperties(_data.Properties);
items = _data.Items;
}
_evaluationLoggingContext.LogProjectEvaluationFinished(globalProperties, properties, items, _evaluationProfiler.ProfiledResult);
}
+ private IEnumerable FilterOutEnvironmentDerivedProperties(PropertyDictionary
dictionary)
+ {
+ List
list = new(dictionary.Count);
+ foreach (P p in dictionary)
+ {
+ if (p is EnvironmentDerivedProjectPropertyInstance ||
+ (p is ProjectProperty pp && pp.IsEnvironmentProperty))
+ {
+ continue;
+ }
+
+ list.Add(p);
+ }
+
+ return list;
+ }
+
private void CollectProjectCachePlugins()
{
foreach (var item in _data.GetItems(ItemTypeNames.ProjectCachePlugin))
@@ -1051,8 +1069,8 @@ private void ReadTargetElement(ProjectTargetElement targetElement, LinkedList
private void AddBeforeAndAfterTargetMappings(ProjectTargetElement targetElement, Dictionary> activeTargets, Dictionary> targetsWhichRunBeforeByTarget, Dictionary> targetsWhichRunAfterByTarget)
{
- var beforeTargets = _expander.ExpandIntoStringListLeaveEscaped(targetElement.BeforeTargets, ExpanderOptions.ExpandPropertiesAndItems, targetElement.BeforeTargetsLocation);
- var afterTargets = _expander.ExpandIntoStringListLeaveEscaped(targetElement.AfterTargets, ExpanderOptions.ExpandPropertiesAndItems, targetElement.AfterTargetsLocation);
+ var beforeTargets = _expander.ExpandIntoStringListLeaveEscaped(targetElement.BeforeTargets, ExpanderOptions.ExpandPropertiesAndItems, targetElement.BeforeTargetsLocation, _evaluationLoggingContext);
+ var afterTargets = _expander.ExpandIntoStringListLeaveEscaped(targetElement.AfterTargets, ExpanderOptions.ExpandPropertiesAndItems, targetElement.AfterTargetsLocation, _evaluationLoggingContext);
foreach (string beforeTarget in beforeTargets)
{
@@ -1197,7 +1215,7 @@ private void AddEnvironmentProperties()
{
foreach (ProjectPropertyInstance environmentProperty in _environmentProperties)
{
- _data.SetProperty(environmentProperty.Name, ((IProperty)environmentProperty).EvaluatedValueEscaped, isGlobalProperty: false, mayBeReserved: false, isEnvironmentVariable: true);
+ _data.SetProperty(environmentProperty.Name, ((IProperty)environmentProperty).EvaluatedValueEscaped, isGlobalProperty: false, mayBeReserved: false, isEnvironmentVariable: true, loggingContext: _evaluationLoggingContext);
}
}
@@ -1298,7 +1316,7 @@ private void EvaluatePropertyElement(ProjectPropertyElement propertyElement)
// it is the same as what we are setting the value on. Note: This needs to be set before we expand the property we are currently setting.
_expander.UsedUninitializedProperties.CurrentlyEvaluatingPropertyElementName = propertyElement.Name;
- string evaluatedValue = _expander.ExpandIntoStringLeaveEscaped(propertyElement.Value, ExpanderOptions.ExpandProperties, propertyElement.Location);
+ string evaluatedValue = _expander.ExpandIntoStringLeaveEscaped(propertyElement.Value, ExpanderOptions.ExpandProperties, propertyElement.Location, _evaluationLoggingContext);
// If we are going to set a property to a value other than null or empty we need to check to see if it has been used
// during evaluation.
@@ -2003,7 +2021,7 @@ private LoadImportsResult ExpandAndLoadImportsFromUnescapedImportExpression(stri
{
imports = null;
- string importExpressionEscaped = _expander.ExpandIntoStringLeaveEscaped(unescapedExpression, ExpanderOptions.ExpandProperties, importElement.ProjectLocation);
+ string importExpressionEscaped = _expander.ExpandIntoStringLeaveEscaped(unescapedExpression, ExpanderOptions.ExpandProperties, importElement.ProjectLocation, _evaluationLoggingContext);
ElementLocation importLocationInProject = importElement.Location;
if (String.IsNullOrWhiteSpace(importExpressionEscaped))
@@ -2428,7 +2446,8 @@ private bool EvaluateCondition(ProjectElement element, string condition, Expande
element.ConditionLocation,
_evaluationLoggingContext.LoggingService,
_evaluationLoggingContext.BuildEventContext,
- _evaluationContext.FileSystem
+ _evaluationContext.FileSystem,
+ loggingContext: _evaluationLoggingContext
);
return result;
diff --git a/src/Build/Evaluation/Expander.cs b/src/Build/Evaluation/Expander.cs
index 46b24084309..5c60e58b0ed 100644
--- a/src/Build/Evaluation/Expander.cs
+++ b/src/Build/Evaluation/Expander.cs
@@ -28,6 +28,7 @@
using TaskItemFactory = Microsoft.Build.Execution.ProjectItemInstance.TaskItem.TaskItemFactory;
using Microsoft.NET.StringTools;
+using Microsoft.Build.BackEnd.Logging;
#nullable disable
@@ -420,9 +421,9 @@ internal static bool ExpressionContainsItemVector(string expression)
///
/// If ExpanderOptions.BreakOnNotEmpty was passed, expression was going to be non-empty, and it broke out early, returns null. Otherwise the result can be trusted.
///
- internal string ExpandIntoStringAndUnescape(string expression, ExpanderOptions options, IElementLocation elementLocation)
+ internal string ExpandIntoStringAndUnescape(string expression, ExpanderOptions options, IElementLocation elementLocation, LoggingContext loggingContext = null)
{
- string result = ExpandIntoStringLeaveEscaped(expression, options, elementLocation);
+ string result = ExpandIntoStringLeaveEscaped(expression, options, elementLocation, loggingContext);
return (result == null) ? null : EscapingUtilities.UnescapeAll(result);
}
@@ -434,7 +435,7 @@ internal string ExpandIntoStringAndUnescape(string expression, ExpanderOptions o
///
/// If ExpanderOptions.BreakOnNotEmpty was passed, expression was going to be non-empty, and it broke out early, returns null. Otherwise the result can be trusted.
///
- internal string ExpandIntoStringLeaveEscaped(string expression, ExpanderOptions options, IElementLocation elementLocation)
+ internal string ExpandIntoStringLeaveEscaped(string expression, ExpanderOptions options, IElementLocation elementLocation, LoggingContext loggingContext = null)
{
if (expression.Length == 0)
{
@@ -444,7 +445,7 @@ internal string ExpandIntoStringLeaveEscaped(string expression, ExpanderOptions
ErrorUtilities.VerifyThrowInternalNull(elementLocation, nameof(elementLocation));
string result = MetadataExpander.ExpandMetadataLeaveEscaped(expression, _metadata, options, elementLocation);
- result = PropertyExpander
.ExpandPropertiesLeaveEscaped(result, _properties, options, elementLocation, _usedUninitializedProperties, _fileSystem);
+ result = PropertyExpander
.ExpandPropertiesLeaveEscaped(result, _properties, options, elementLocation, _usedUninitializedProperties, _fileSystem, loggingContext);
result = ItemExpander.ExpandItemVectorsIntoString(this, result, _items, options, elementLocation);
result = FileUtilities.MaybeAdjustFilePath(result);
@@ -474,11 +475,11 @@ internal object ExpandPropertiesLeaveTypedAndEscaped(string expression, Expander
/// Use this form when the result is going to be processed further, for example by matching against the file system,
/// so literals must be distinguished, and you promise to unescape after that.
///
- internal SemiColonTokenizer ExpandIntoStringListLeaveEscaped(string expression, ExpanderOptions options, IElementLocation elementLocation)
+ internal SemiColonTokenizer ExpandIntoStringListLeaveEscaped(string expression, ExpanderOptions options, IElementLocation elementLocation, LoggingContext loggingContext = null)
{
ErrorUtilities.VerifyThrow((options & ExpanderOptions.BreakOnNotEmpty) == 0, "not supported");
- return ExpressionShredder.SplitSemiColonSeparatedList(ExpandIntoStringLeaveEscaped(expression, options, elementLocation));
+ return ExpressionShredder.SplitSemiColonSeparatedList(ExpandIntoStringLeaveEscaped(expression, options, elementLocation, loggingContext));
}
///
@@ -1078,7 +1079,8 @@ internal static string ExpandPropertiesLeaveEscaped(
ExpanderOptions options,
IElementLocation elementLocation,
UsedUninitializedProperties usedUninitializedProperties,
- IFileSystem fileSystem)
+ IFileSystem fileSystem,
+ LoggingContext loggingContext = null)
{
return
ConvertToString(
@@ -1088,7 +1090,8 @@ internal static string ExpandPropertiesLeaveEscaped(
options,
elementLocation,
usedUninitializedProperties,
- fileSystem));
+ fileSystem,
+ loggingContext));
}
///
@@ -1114,7 +1117,8 @@ internal static object ExpandPropertiesLeaveTypedAndEscaped(
ExpanderOptions options,
IElementLocation elementLocation,
UsedUninitializedProperties usedUninitializedProperties,
- IFileSystem fileSystem)
+ IFileSystem fileSystem,
+ LoggingContext loggingContext = null)
{
if (((options & ExpanderOptions.ExpandProperties) == 0) || String.IsNullOrEmpty(expression))
{
@@ -1229,7 +1233,7 @@ internal static object ExpandPropertiesLeaveTypedAndEscaped(
}
else // This is a regular property
{
- propertyValue = LookupProperty(properties, expression, propertyStartIndex + 2, propertyEndIndex - 1, elementLocation, usedUninitializedProperties);
+ propertyValue = LookupProperty(properties, expression, propertyStartIndex + 2, propertyEndIndex - 1, elementLocation, usedUninitializedProperties, loggingContext);
}
if (propertyValue != null)
@@ -1467,7 +1471,7 @@ private static object LookupProperty(IPropertyProvider properties, string pro
///
/// Look up a simple property reference by the name of the property, e.g. "Foo" when expanding $(Foo).
///
- private static object LookupProperty(IPropertyProvider properties, string propertyName, int startIndex, int endIndex, IElementLocation elementLocation, UsedUninitializedProperties usedUninitializedProperties)
+ private static object LookupProperty(IPropertyProvider properties, string propertyName, int startIndex, int endIndex, IElementLocation elementLocation, UsedUninitializedProperties usedUninitializedProperties, LoggingContext loggingContext = null)
{
T property = properties.GetProperty(propertyName, startIndex, endIndex);
@@ -1512,6 +1516,11 @@ private static object LookupProperty(IPropertyProvider properties, string pro
}
else
{
+ if (property is ProjectPropertyInstance.EnvironmentDerivedProjectPropertyInstance environmentDerivedProperty)
+ {
+ environmentDerivedProperty.loggingContext = loggingContext;
+ }
+
propertyValue = property.EvaluatedValueEscaped;
}
diff --git a/src/Build/Evaluation/IEvaluatorData.cs b/src/Build/Evaluation/IEvaluatorData.cs
index cf0b17d457f..497207e7024 100644
--- a/src/Build/Evaluation/IEvaluatorData.cs
+++ b/src/Build/Evaluation/IEvaluatorData.cs
@@ -267,7 +267,7 @@ List EvaluatedItemElements
///
/// Sets a property which does not come from the Xml.
///
- P SetProperty(string name, string evaluatedValueEscaped, bool isGlobalProperty, bool mayBeReserved, bool isEnvironmentVariable = false);
+ P SetProperty(string name, string evaluatedValueEscaped, bool isGlobalProperty, bool mayBeReserved, bool isEnvironmentVariable = false, BackEnd.Logging.LoggingContext loggingContext = null);
///
/// Sets a property which comes from the Xml.
diff --git a/src/Build/Evaluation/ItemSpec.cs b/src/Build/Evaluation/ItemSpec.cs
index 65c1fd8b486..d7f58c8088a 100644
--- a/src/Build/Evaluation/ItemSpec.cs
+++ b/src/Build/Evaluation/ItemSpec.cs
@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using Microsoft.Build.BackEnd.Logging;
using Microsoft.Build.Globbing;
using Microsoft.Build.Internal;
using Microsoft.Build.Shared;
@@ -156,21 +157,23 @@ private bool InitReferencedItemsIfNecessary()
/// The xml location the itemspec comes from
/// The directory that the project is in.
/// Expand properties before breaking down fragments. Defaults to true
+ /// Context in which to log
public ItemSpec(
string itemSpec,
Expander