diff --git a/documentation/ProjectReference-Protocol.md b/documentation/ProjectReference-Protocol.md index 8cd28cc499d..5e2a138e3d5 100644 --- a/documentation/ProjectReference-Protocol.md +++ b/documentation/ProjectReference-Protocol.md @@ -106,6 +106,8 @@ As of MSBuild 16.10, it is possible to gather additional properties from referen These properties will then be gathered via the `GetTargetFrameworks` call. They will be available to the referencing project via the `AdditionalPropertiesFromProject` metadata on the `_MSBuildProjectReferenceExistent` item. The `AdditionalPropertiesFromProject` value will be an XML string which contains the values of the properties for each `TargetFramework` in the referenced project. For example: +> :warning: This format is being changed. Soon, the schema will replace with . You can opt into that behavior early by setting the _UseAttributeForTargetFrameworkInfoPropertyNames property to true. This property will have no effect after the transition is complete. + ```xml diff --git a/ref/Microsoft.Build.Tasks.Core/net/Microsoft.Build.Tasks.Core.cs b/ref/Microsoft.Build.Tasks.Core/net/Microsoft.Build.Tasks.Core.cs index bbd015301c6..0c71f5d7390 100644 --- a/ref/Microsoft.Build.Tasks.Core/net/Microsoft.Build.Tasks.Core.cs +++ b/ref/Microsoft.Build.Tasks.Core/net/Microsoft.Build.Tasks.Core.cs @@ -164,6 +164,7 @@ public partial class CombineTargetFrameworkInfoProperties : Microsoft.Build.Task [Microsoft.Build.Framework.OutputAttribute] public string Result { get { throw null; } set { } } public string RootElementName { get { throw null; } set { } } + public bool UseAttributeForTargetFrameworkInfoPropertyNames { get { throw null; } set { } } public override bool Execute() { throw null; } } public partial class CombineXmlElements : Microsoft.Build.Tasks.TaskExtension diff --git a/ref/Microsoft.Build.Tasks.Core/netstandard/Microsoft.Build.Tasks.Core.cs b/ref/Microsoft.Build.Tasks.Core/netstandard/Microsoft.Build.Tasks.Core.cs index 197ce5ff14b..032e84fecf9 100644 --- a/ref/Microsoft.Build.Tasks.Core/netstandard/Microsoft.Build.Tasks.Core.cs +++ b/ref/Microsoft.Build.Tasks.Core/netstandard/Microsoft.Build.Tasks.Core.cs @@ -94,6 +94,7 @@ public partial class CombineTargetFrameworkInfoProperties : Microsoft.Build.Task [Microsoft.Build.Framework.OutputAttribute] public string Result { get { throw null; } set { } } public string RootElementName { get { throw null; } set { } } + public bool UseAttributeForTargetFrameworkInfoPropertyNames { get { throw null; } set { } } public override bool Execute() { throw null; } } public partial class CombineXmlElements : Microsoft.Build.Tasks.TaskExtension diff --git a/src/Tasks/CombineTargetFrameworkInfoProperties.cs b/src/Tasks/CombineTargetFrameworkInfoProperties.cs index 612f27d3b88..bfd7caae236 100644 --- a/src/Tasks/CombineTargetFrameworkInfoProperties.cs +++ b/src/Tasks/CombineTargetFrameworkInfoProperties.cs @@ -2,11 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using Microsoft.Build.Framework; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Microsoft.Build.Shared; using System.Xml.Linq; namespace Microsoft.Build.Tasks @@ -26,6 +22,11 @@ public class CombineTargetFrameworkInfoProperties : TaskExtension /// public ITaskItem[] PropertiesAndValues { get; set; } + /// + /// Opts into or out of using the new schema with Property Name=... rather than just specifying the RootElementName. + /// + public bool UseAttributeForTargetFrameworkInfoPropertyNames { get; set; } = false; + /// /// The generated XML representation of the properties and values. /// @@ -36,9 +37,11 @@ public override bool Execute() { if (PropertiesAndValues != null) { - XElement root = new XElement(RootElementName); + XElement root = UseAttributeForTargetFrameworkInfoPropertyNames ? + new("TargetFramework", new XAttribute("Name", EscapingUtilities.Escape(RootElementName))) : + new(RootElementName); - foreach (var item in PropertiesAndValues) + foreach (ITaskItem item in PropertiesAndValues) { root.Add(new XElement(item.ItemSpec, item.GetMetadata("Value"))); } diff --git a/src/Tasks/CombineXmlElements.cs b/src/Tasks/CombineXmlElements.cs index c42aed7f1bd..214207b1b6e 100644 --- a/src/Tasks/CombineXmlElements.cs +++ b/src/Tasks/CombineXmlElements.cs @@ -2,11 +2,6 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using Microsoft.Build.Framework; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Xml.Linq; namespace Microsoft.Build.Tasks diff --git a/src/Tasks/Microsoft.Common.CurrentVersion.targets b/src/Tasks/Microsoft.Common.CurrentVersion.targets index 8cb9228276d..1262c54d61a 100644 --- a/src/Tasks/Microsoft.Common.CurrentVersion.targets +++ b/src/Tasks/Microsoft.Common.CurrentVersion.targets @@ -1906,9 +1906,14 @@ Copyright (C) Microsoft Corporation. All rights reserved. + + <_UseAttributeForTargetFrameworkInfoPropertyNames Condition="'$(_UseAttributeForTargetFrameworkInfoPropertyNames)' == ''">false + + + PropertiesAndValues="@(_AdditionalTargetFrameworkInfoPropertyWithValue)" + UseAttributeForTargetFrameworkInfoPropertyNames="$(_UseAttributeForTargetFrameworkInfoPropertyNames)">