forked from anthonylangsworth/corefx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildvertical.targets
113 lines (97 loc) · 5.25 KB
/
buildvertical.targets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="FindBestConfiguration" AssemblyFile="$(CoreFxToolsTaskDir)CoreFx.Tools.dll"/>
<PropertyGroup>
<ImportedBuildVerticalTargets>true</ImportedBuildVerticalTargets>
</PropertyGroup>
<!-- Import configuration data model -->
<Import Project="$(MSBuildThisFileDirectory)src/Tools/GenerateProps/properties.props" />
<!-- Runs during traversal to select which projects and configurations of those projects to build -->
<Target Name="AnnotateAndFilterProjects"
BeforeTargets="BuildAllProjects;TestAllProjects">
<!-- find the best configuration for each project, projects that shouldn't build for this configuration
return an empty item. -->
<MSBuild Targets="FindBestConfiguration"
Projects="@(Project)"
Condition="'$(BuildAllConfigurations)' != 'true'">
<Output TaskParameter="TargetOutputs"
ItemName="_ProjectBestConfigurations" />
</MSBuild>
<MSBuild Targets="GetBuildConfigurations"
Projects="@(Project)"
Condition="'$(BuildAllConfigurations)' == 'true'">
<Output TaskParameter="TargetOutputs"
ItemName="_ProjectBestConfigurations" />
</MSBuild>
<ItemGroup>
<!-- transform back to project -->
<ProjectWithConfiguration Include="@(_ProjectBestConfigurations->'%(OriginalItemSpec)')">
<AdditionalProperties>Configuration=%(Identity);%(_ProjectBestConfigurations.AdditionalProperties)</AdditionalProperties>
</ProjectWithConfiguration>
</ItemGroup>
<ItemGroup>
<Project Remove="@(Project)" />
<Project Include="@(ProjectWithConfiguration)" />
</ItemGroup>
</Target>
<!-- Runs in a leaf project (eg: csproj) to determine best configuration if one exists for purposes of filtering -->
<Target Name="FindBestConfiguration"
Returns="$(_BestConfiguration)">
<!-- if BuildConfigurations is defined, find the best one -->
<FindBestConfiguration Condition="'$(BuildConfigurations)' != ''"
Properties="@(Property)"
PropertyValues="@(PropertyValue)"
BuildConfigurations="$(BuildConfigurations)"
BuildConfiguration="$(BuildConfiguration)">
<Output TaskParameter="BestConfiguration" PropertyName="_BestConfiguration" />
</FindBestConfiguration>
<!-- if BuildConfigurations is not defined, use BuildConfiguration -->
<PropertyGroup>
<_BestConfiguration Condition="'$(BuildConfigurations)' == ''">$(BuildConfiguration)</_BestConfiguration>
</PropertyGroup>
</Target>
<!-- Runs in a leaf project (eg: csproj) to determine all configurations -->
<Target Name="GetBuildConfigurations"
Returns="$(_AllBuildConfigurations)">
<PropertyGroup>
<_AllBuildConfigurations>$(BuildConfigurations)</_AllBuildConfigurations>
<_AllBuildConfigurations Condition="'$(BuildConfigurations)' == ''">$(BuildConfiguration)</_AllBuildConfigurations>
</PropertyGroup>
</Target>
<!-- Runs in a leaf project (csproj) to determine best configuration for ProjectReferences -->
<Target Name="AnnotateProjectReference"
BeforeTargets="BeforeResolveReferences"
Condition="'@(ProjectReference)' != ''"
Inputs="%(ProjectReference.Identity)"
Outputs="unused">
<!-- Get all configurations for each ProjectReference. We use this
rather than the FindBestConfiguration target since we need to
choose the best configuration for the referencing project's
configuration, not the BuildConfiguration. -->
<MSBuild Targets="GetBuildConfigurations"
Projects="@(ProjectReference)">
<Output TaskParameter="TargetOutputs" PropertyName="_projectReferenceBuildConfigurations" />
</MSBuild>
<!-- Find the best configuration for the current Project's Configuration -->
<FindBestConfiguration Properties="@(Property)"
PropertyValues="@(PropertyValue)"
BuildConfigurations="$(_ProjectReferenceBuildConfigurations)"
BuildConfiguration="$(Configuration)">
<Output TaskParameter="BestConfiguration" PropertyName="_projectReferenceConfiguration" />
</FindBestConfiguration>
<Error Condition="'$(_projectReferenceConfiguration)' == ''" Text="Could not find a configuration for ProjectReference '@(ProjectReference)' from configurations '$(_projectReferenceBuildConfigurations)' when building '$(MSBuildProjectName)' for configuration '$(Configuration)' ." />
<ItemGroup>
<ProjectReference>
<AdditionalProperties>Configuration=$(_projectReferenceConfiguration);%(ProjectReference.AdditionalProperties)</AdditionalProperties>
</ProjectReference>
</ItemGroup>
</Target>
<Target Name="BuildAll">
<ItemGroup>
<_buildConfigurations Include="$(BuildConfigurations)" />
<_buildConfigurations Condition="'@(_buildConfigurations)' == ''" Include="$(BuildConfiguration)" />
</ItemGroup>
<MSBuild Projects="$(MSBuildProjectFullPath)"
Properties="Configuration=%(_buildConfigurations.Identity)" />
</Target>
</Project>