diff --git a/src/Build/Evaluation/ExpressionShredder.cs b/src/Build/Evaluation/ExpressionShredder.cs index a7d9e48b9a5..9ec23207b31 100644 --- a/src/Build/Evaluation/ExpressionShredder.cs +++ b/src/Build/Evaluation/ExpressionShredder.cs @@ -300,9 +300,9 @@ private static void GetReferencedItemNamesAndMetadata(string expression, int sta i--; } - // Grab the name, but continue to verify it's a well-formed expression + // Grab the name boundaries, but continue to verify it's a well-formed expression // before we store it. - string name = expression.Substring(startOfName, i - startOfName); + int nameLength = i - startOfName; SinkWhitespace(expression, ref i); @@ -378,7 +378,7 @@ private static void GetReferencedItemNamesAndMetadata(string expression, int sta if ((whatToShredFor & ShredderOptions.ItemTypes) != 0) { pair.Items ??= new HashSet(MSBuildNameIgnoreCaseComparer.Default); - pair.Items.Add(name); + pair.Items.Add(expression.Substring(startOfName, nameLength)); } i--;