Skip to content

Commit

Permalink
Identify inner-build in consuming project
Browse files Browse the repository at this point in the history
* Call GetTargetFrameworks target to identify target frameworks in
referenced projects. Since TargetFrameworks is not set, this will avoid
a 2nd evaluation when the project single targets.

* Adds dependency on NuGet AssignReferenceProperties task.
  • Loading branch information
rainersigwald authored and AndyGerlicher committed Oct 6, 2017
1 parent c36bfb3 commit 3eb23d3
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 14 deletions.
13 changes: 13 additions & 0 deletions src/Tasks/Microsoft.Common.CrossTargeting.targets
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ Copyright (C) Microsoft Corporation. All rights reserved.

<Import Project="$(CustomBeforeMicrosoftCommonCrossTargetingTargets)" Condition="'$(CustomBeforeMicrosoftCommonCrossTargetingTargets)' != '' and Exists('$(CustomBeforeMicrosoftCommonCrossTargetingTargets)')"/>

<Target Name="GetTargetFrameworks"
Returns="@(_ThisProjectBuildMetadata)">
<ItemGroup>
<_ThisProjectBuildMetadata Include="$(MSBuildProjectFullPath)">
<TargetFrameworks Condition="'$(TargetFrameworks)' != ''">$(TargetFrameworks)</TargetFrameworks>
<TargetFrameworks Condition="'$(TargetFrameworks)' == ''">$(TargetFramework)</TargetFrameworks>
<HasSingleTargetFramework>true</HasSingleTargetFramework>
<HasSingleTargetFramework Condition="'$(IsCrossTargetingBuild)' == 'true'">false</HasSingleTargetFramework>
<IsRidAgnostic>true</IsRidAgnostic>
</_ThisProjectBuildMetadata>
</ItemGroup>
</Target>

<Target Name="_ComputeTargetFrameworkItems" Returns="@(InnerOutput)">
<ItemGroup>
<_TargetFramework Include="$(TargetFrameworks)" />
Expand Down
70 changes: 56 additions & 14 deletions src/Tasks/Microsoft.Common.CurrentVersion.targets
Original file line number Diff line number Diff line change
Expand Up @@ -1512,20 +1512,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.

</Target>

<!--
====================================================================================
_GetProjectReferenceTargetFrameworkProperties
Builds the GetTargetFrameworkProperties target of all existent project references,
passing $(TargetFrameworkMoniker) as $(ReferringTargetFramework) and sets the
SetTargetFramework metadata of the project reference to the value that is returned.
This allows a cross-targeting project to select how it should be configured to
build against the most appropriate target for the referring target framework.
======================================================================================
-->
<Target Name="_GetProjectReferenceTargetFrameworkProperties">
<Target Name="_ComputeProjectReferenceTargetFrameworkMatches" BeforeTargets="_GetProjectReferenceTargetFrameworkProperties">
<!--
Honor SkipGetTargetFrameworkProperties=true metadata on project references
to mean that the project reference is known not to target multiple frameworks
Expand Down Expand Up @@ -1557,6 +1544,61 @@ Copyright (C) Microsoft Corporation. All rights reserved.
</_MSBuildProjectReferenceExistent>
</ItemGroup>

<!-- Get reference target framework lists -->
<MSBuild
Projects="@(_MSBuildProjectReferenceExistent)"
Targets="GetTargetFrameworks"
BuildInParallel="$(BuildInParallel)"
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform)"
ContinueOnError="!$(BuildingProject)"
RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove);TargetFramework;RuntimeIdentifier"
Condition="'%(_MSBuildProjectReferenceExistent.SkipGetTargetFrameworkProperties)' != 'true'"
SkipNonexistentTargets="true">
<Output TaskParameter="TargetOutputs" ItemName="_ProjectReferenceTargetFrameworkPossibilities" />
</MSBuild>

<!-- For each reference, get closest match -->
<AssignReferenceProperties AnnotatedProjectReferences="@(_ProjectReferenceTargetFrameworkPossibilities)"
CurrentProjectTargetFramework="$(TargetFrameworkMoniker)"
Condition="'@(_ProjectReferenceTargetFrameworkPossibilities->Count())' != '0'">
<Output ItemName="AnnotatedProjects" TaskParameter="AssignedProjects" />
</AssignReferenceProperties>

<ItemGroup>
<_MSBuildProjectReferenceExistent Remove="@(_MSBuildProjectReferenceExistent)" />
<_MSBuildProjectReferenceExistent Include="@(AnnotatedProjects)" />
</ItemGroup>

<!-- Assign metadata to ProjectReferences, including skipping old-style TF checks. -->
</Target>

<Target Name="GetTargetFrameworks"
Returns="@(_ThisProjectBuildMetadata)">
<ItemGroup>
<_ThisProjectBuildMetadata Include="$(MSBuildProjectFullPath)">
<TargetFrameworks Condition="'$(TargetFrameworks)' != ''">$(TargetFrameworks)</TargetFrameworks>
<TargetFrameworks Condition="'$(TargetFrameworks)' == ''">$(TargetFramework)</TargetFrameworks>
<HasSingleTargetFramework>true</HasSingleTargetFramework>
<HasSingleTargetFramework Condition="'$(IsCrossTargetingBuild)' == 'true'">false</HasSingleTargetFramework>
<IsRidAgnostic>true</IsRidAgnostic>
</_ThisProjectBuildMetadata>
</ItemGroup>
</Target>

<!--
====================================================================================
_GetProjectReferenceTargetFrameworkProperties
Builds the GetTargetFrameworkProperties target of all existent project references,
passing $(TargetFrameworkMoniker) as $(ReferringTargetFramework) and sets the
SetTargetFramework metadata of the project reference to the value that is returned.
This allows a cross-targeting project to select how it should be configured to
build against the most appropriate target for the referring target framework.
======================================================================================
-->
<Target Name="_GetProjectReferenceTargetFrameworkProperties">
<!--
Select the moniker to send to each project reference if not already set. NugetTargetMoniker (NTM) is preferred by default over
TargetFrameworkMoniker (TFM) because it is required to disambiguate the UWP case where TFM is fixed at .NETCore,Version=v5.0 and
Expand Down

0 comments on commit 3eb23d3

Please sign in to comment.