Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support gathering additional arbitrary properties from referenced projects #5994

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions ref/Microsoft.Build.Tasks.Core/net/Microsoft.Build.Tasks.Core.cs
Expand Up @@ -157,6 +157,24 @@ public partial class CombinePath : Microsoft.Build.Tasks.TaskExtension
public Microsoft.Build.Framework.ITaskItem[] Paths { get { throw null; } set { } }
public override bool Execute() { throw null; }
}
public partial class CombineTargetFrameworkInfoProperties : Microsoft.Build.Tasks.TaskExtension
{
public CombineTargetFrameworkInfoProperties() { }
public Microsoft.Build.Framework.ITaskItem[] PropertiesAndValues { get { throw null; } set { } }
[Microsoft.Build.Framework.OutputAttribute]
public string Result { get { throw null; } set { } }
public string RootElementName { get { throw null; } set { } }
public override bool Execute() { throw null; }
}
public partial class CombineXmlElements : Microsoft.Build.Tasks.TaskExtension
{
public CombineXmlElements() { }
[Microsoft.Build.Framework.OutputAttribute]
public string Result { get { throw null; } set { } }
public string RootElementName { get { throw null; } set { } }
public Microsoft.Build.Framework.ITaskItem[] XmlElements { get { throw null; } set { } }
public override bool Execute() { throw null; }
}
public partial class CommandLineBuilderExtension : Microsoft.Build.Utilities.CommandLineBuilder
{
public CommandLineBuilderExtension() { }
Expand Down
Expand Up @@ -87,6 +87,24 @@ public partial class CombinePath : Microsoft.Build.Tasks.TaskExtension
public Microsoft.Build.Framework.ITaskItem[] Paths { get { throw null; } set { } }
public override bool Execute() { throw null; }
}
public partial class CombineTargetFrameworkInfoProperties : Microsoft.Build.Tasks.TaskExtension
{
public CombineTargetFrameworkInfoProperties() { }
public Microsoft.Build.Framework.ITaskItem[] PropertiesAndValues { get { throw null; } set { } }
[Microsoft.Build.Framework.OutputAttribute]
public string Result { get { throw null; } set { } }
public string RootElementName { get { throw null; } set { } }
public override bool Execute() { throw null; }
}
public partial class CombineXmlElements : Microsoft.Build.Tasks.TaskExtension
{
public CombineXmlElements() { }
[Microsoft.Build.Framework.OutputAttribute]
public string Result { get { throw null; } set { } }
public string RootElementName { get { throw null; } set { } }
public Microsoft.Build.Framework.ITaskItem[] XmlElements { get { throw null; } set { } }
public override bool Execute() { throw null; }
}
public partial class CommandLineBuilderExtension : Microsoft.Build.Utilities.CommandLineBuilder
{
public CommandLineBuilderExtension() { }
Expand Down
34 changes: 34 additions & 0 deletions src/Tasks/CombineTargetFrameworkInfoProperties.cs
@@ -0,0 +1,34 @@
using Microsoft.Build.Framework;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copyright header

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace Microsoft.Build.Tasks
{
public class CombineTargetFrameworkInfoProperties : TaskExtension
{
public string RootElementName { get; set; }

public ITaskItem[] PropertiesAndValues { get; set; }

[Output]
public string Result { get; set; }

public override bool Execute()
{
XElement root = new XElement(RootElementName);

foreach (var item in PropertiesAndValues)
{
root.Add(new XElement(item.ItemSpec, item.GetMetadata("Value")));
}

Result = root.ToString();

return true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return !HasLoggedErrors? Same below.

}
}
}
34 changes: 34 additions & 0 deletions src/Tasks/CombineXmlElements.cs
@@ -0,0 +1,34 @@
using Microsoft.Build.Framework;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copyright header

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace Microsoft.Build.Tasks
{
public class CombineXmlElements : TaskExtension
{
public string RootElementName { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required annotations for these?


public ITaskItem [] XmlElements { get; set; }

[Output]
public string Result { get; set; }

public override bool Execute()
{
XElement root = new XElement(RootElementName);

foreach (var item in XmlElements)
{
root.Add(XElement.Parse(item.ItemSpec));
}

Result = root.ToString();

return true;
}
}
}
2 changes: 2 additions & 0 deletions src/Tasks/Microsoft.Build.Tasks.csproj
Expand Up @@ -61,6 +61,8 @@
<ExcludeFromStyleCop>True</ExcludeFromStyleCop>
</Compile>
<Compile Include="AssemblyDependency\AssemblyMetadata.cs" />
<Compile Include="CombineTargetFrameworkInfoProperties.cs" />
<Compile Include="CombineXmlElements.cs" />
<Compile Include="ConvertToAbsolutePath.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
Expand Down
8 changes: 8 additions & 0 deletions src/Tasks/Microsoft.Common.CrossTargeting.targets
Expand Up @@ -26,12 +26,20 @@ Copyright (C) Microsoft Corporation. All rights reserved.

<Error Condition="'$(IsCrossTargetingBuild)' != 'true'"
Text="Internal MSBuild error: CrossTargeting GetTargetFrameworks target should only be used in cross targeting (outer) build" />

<CombineXmlElements
RootElementName="AdditionalProjectProperties"
XmlElements="@(_TargetFrameworkInfo->'%(AdditionalPropertiesFromProject)')">
<Output TaskParameter="Result"
PropertyName="_AdditionalPropertiesFromProject"/>
</CombineXmlElements>

<ItemGroup>
<_ThisProjectBuildMetadata Include="$(MSBuildProjectFullPath)">
<TargetFrameworks>@(_TargetFrameworkInfo)</TargetFrameworks>
<TargetFrameworkMonikers>@(_TargetFrameworkInfo->'%(TargetFrameworkMonikers)')</TargetFrameworkMonikers>
<TargetPlatformMonikers>@(_TargetFrameworkInfo->'%(TargetPlatformMonikers)')</TargetPlatformMonikers>
<AdditionalPropertiesFromProject>$(_AdditionalPropertiesFromProject)</AdditionalPropertiesFromProject>

<HasSingleTargetFramework>false</HasSingleTargetFramework>

Expand Down
22 changes: 22 additions & 0 deletions src/Tasks/Microsoft.Common.CurrentVersion.targets
Expand Up @@ -1725,11 +1725,19 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<Error Condition="'$(IsCrossTargetingBuild)' == 'true'"
Text="Internal MSBuild error: Non-CrossTargeting GetTargetFrameworks target should not be used in cross targeting (outer) build" />

<CombineXmlElements
RootElementName="AdditionalProjectProperties"
XmlElements="@(_TargetFrameworkInfo->'%(AdditionalPropertiesFromProject)')">
<Output TaskParameter="Result"
PropertyName="_AdditionalPropertiesFromProject"/>
</CombineXmlElements>

<ItemGroup>
<_ThisProjectBuildMetadata Include="$(MSBuildProjectFullPath)">
<TargetFrameworks>@(_TargetFrameworkInfo)</TargetFrameworks>
<TargetFrameworkMonikers>@(_TargetFrameworkInfo->'%(TargetFrameworkMonikers)')</TargetFrameworkMonikers>
<TargetPlatformMonikers>@(_TargetFrameworkInfo->'%(TargetPlatformMonikers)')</TargetPlatformMonikers>
<AdditionalPropertiesFromProject>$(_AdditionalPropertiesFromProject)</AdditionalPropertiesFromProject>

<HasSingleTargetFramework>true</HasSingleTargetFramework>

Expand All @@ -1743,12 +1751,26 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<Target Name="GetTargetFrameworksWithPlatformForSingleTargetFramework"
Returns="@(_TargetFrameworkInfo)">

<ItemGroup>
<_AdditionalTargetFrameworkInfoPropertyWithValue Include="@(AdditionalTargetFrameworkInfoProperty)">
<Value>$(%(AdditionalTargetFrameworkInfoProperty.Identity))</Value>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realize you could have a metadata reference as an identifier for a property. Neat!

</_AdditionalTargetFrameworkInfoPropertyWithValue>
</ItemGroup>

<CombineTargetFrameworkInfoProperties
RootElementName="$(TargetFramework)"
PropertiesAndValues="@(_AdditionalTargetFrameworkInfoPropertyWithValue)">
<Output TaskParameter="Result"
PropertyName="_AdditionalTargetFrameworkInfoProperties"/>
</CombineTargetFrameworkInfoProperties>

<ItemGroup>
<_TargetFrameworkInfo Include="$(TargetFramework)">
<TargetFrameworks>$(TargetFramework)</TargetFrameworks>
<TargetFrameworkMonikers>$(TargetFrameworkMoniker)</TargetFrameworkMonikers>
<TargetPlatformMonikers>$(TargetPlatformMoniker)</TargetPlatformMonikers>
<TargetPlatformMonikers Condition="'$(TargetPlatformMoniker)' == ''">None</TargetPlatformMonikers>
<AdditionalPropertiesFromProject>$(_AdditionalTargetFrameworkInfoProperties)</AdditionalPropertiesFromProject>
</_TargetFrameworkInfo>
</ItemGroup>

Expand Down
2 changes: 2 additions & 0 deletions src/Tasks/Microsoft.Common.tasks
Expand Up @@ -95,6 +95,8 @@
<UsingTask TaskName="Microsoft.Build.Tasks.CallTarget" AssemblyName="Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Condition="'$(MSBuildAssemblyVersion)' != ''" />
<UsingTask TaskName="Microsoft.Build.Tasks.CombinePath" AssemblyName="Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Condition="'$(MSBuildAssemblyVersion)' != ''" />
<UsingTask TaskName="Microsoft.Build.Tasks.ConvertToAbsolutePath" AssemblyName="Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Condition="'$(MSBuildAssemblyVersion)' != ''" />
<UsingTask TaskName="Microsoft.Build.Tasks.CombineTargetFrameworkInfoProperties" AssemblyName="Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Condition="'$(MSBuildAssemblyVersion)' != ''" />
<UsingTask TaskName="Microsoft.Build.Tasks.CombineXmlElements" AssemblyName="Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Condition="'$(MSBuildAssemblyVersion)' != ''" />
<UsingTask TaskName="Microsoft.Build.Tasks.Copy" AssemblyName="Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Condition="'$(MSBuildAssemblyVersion)' != ''" />
<UsingTask TaskName="Microsoft.Build.Tasks.CreateCSharpManifestResourceName" AssemblyName="Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Condition="'$(MSBuildAssemblyVersion)' != ''" />
<UsingTask TaskName="Microsoft.Build.Tasks.CreateItem" AssemblyName="Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Condition="'$(MSBuildAssemblyVersion)' != ''" />
Expand Down