forked from dotnet/corefx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildvertical.targets
186 lines (157 loc) · 9.46 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="FindBestConfigurations" AssemblyFile="$(CoreFxToolsTaskDir)CoreFx.Tools.dll"/>
<PropertyGroup>
<ImportedBuildVerticalTargets>true</ImportedBuildVerticalTargets>
<_traversalBuildConfigurations>$(BuildConfiguration)</_traversalBuildConfigurations>
<_traversalBuildConfigurations Condition="'$(AdditionalBuildConfigurations)' != ''">$(_traversalBuildConfigurations);$(AdditionalBuildConfigurations)</_traversalBuildConfigurations>
</PropertyGroup>
<!-- Import configuration data model -->
<Import Project="$(MSBuildThisFileDirectory)src/Tools/GenerateProps/properties.props" />
<!-- Runs during traversal when BuildAllConfigurations is set to expand each project
to a seperate instance for each of its BuildConfigurations -->
<Target Name="ExpandAllBuildConfigurations"
Condition="'$(BuildAllConfigurations)' == 'true'">
<MSBuild Targets="GetBuildConfigurations"
Projects="@(Project)"
Condition="'$(BuildAllConfigurations)' == 'true'">
<Output TaskParameter="TargetOutputs"
ItemName="_projectBuildConfigurations" />
</MSBuild>
<ItemGroup>
<!-- assign configuration as a seperate step to prevent batching during the transform which can reorder the list.
order or projects matters here since this applies to traversal projects which build projects serially. -->
<_projectBuildConfigurations>
<AdditionalProperties>Configuration=%(Identity);%(_projectBuildConfigurations.AdditionalProperties)</AdditionalProperties>
</_projectBuildConfigurations>
<!-- transform back to project -->
<_projectWithConfiguration Include="@(_projectBuildConfigurations->'%(OriginalItemSpec)')" />
</ItemGroup>
<ItemGroup>
<Project Remove="@(Project)" />
<Project Include="@(_projectWithConfiguration)" />
</ItemGroup>
</Target>
<Target Name="ExpandAllBuildConfigurationsForPkgProj"
BeforeTargets="ExpandProjectReferences"
Condition="'$(MSBuildProjectExtension)' == '.pkgproj'">
<MSBuild Targets="GetPackageConfigurations"
Projects="@(_NonPkgProjProjectReference)">
<Output TaskParameter="TargetOutputs"
ItemName="_NonPkgProjProjectReferenceBuildConfigurations" />
</MSBuild>
<ItemGroup>
<!-- assign configuration as a seperate step to prevent batching during the transform which can reorder the list.
order or projects matters here since this applies to traversal projects which build projects serially. -->
<_NonPkgProjProjectReferenceBuildConfigurations>
<AdditionalProperties>Configuration=%(Identity);%(_NonPkgProjProjectReferenceBuildConfigurations.AdditionalProperties)</AdditionalProperties>
</_NonPkgProjProjectReferenceBuildConfigurations>
<!-- transform back to project -->
<_NonPkgProjProjectReferenceWitnConfiguration Include="@(_NonPkgProjProjectReferenceBuildConfigurations->'%(OriginalItemSpec)')" />
</ItemGroup>
<ItemGroup>
<_NonPkgProjProjectReference Remove="@(_NonPkgProjProjectReference)" />
<_NonPkgProjProjectReference Include="@(_NonPkgProjProjectReferenceWitnConfiguration)" />
</ItemGroup>
</Target>
<!-- Runs during traversal to select which projects and configurations of those projects to build
Batches over the projects because we need to treat BuildConfigurations as a Property
as well as copy the Project based on results of FindBestConfigurations. -->
<Target Name="FilterBuildConfiguration"
Condition="'$(BuildAllConfigurations)' != 'true'"
Inputs="%(Project.Identity)"
Outputs="unused">
<MSBuild Targets="GetBuildConfigurations"
Projects="@(Project)">
<Output TaskParameter="TargetOutputs"
PropertyName="_projectBuildConfigurations" />
</MSBuild>
<FindBestConfigurations Properties="@(Property)"
PropertyValues="@(PropertyValue)"
SupportedConfigurations="$(_projectBuildConfigurations)"
Configurations="$(_traversalBuildConfigurations)">
<Output TaskParameter="BestConfigurations" ItemName="_projectBestConfigurations" />
</FindBestConfigurations>
<ItemGroup>
<!-- Apply configuration, this does a catesian product between @(Project) and @(_projectBestConfigurations) -->
<_projectWithConfiguration Include="@(Project)" Condition="'@(_projectBestConfigurations)' != ''">
<AdditionalProperties>Configuration=%(_projectBestConfigurations.Identity);%(_projectWithConfiguration.AdditionalProperties)</AdditionalProperties>
</_projectWithConfiguration>
<Project Remove="@(Project)"/>
<Project Include="@(_projectWithConfiguration)"/>
</ItemGroup>
</Target>
<Target Name="FilterProjects"
Condition="'$(FilterProjectsByBuildConfiguration)' != 'false'"
DependsOnTargets="ExpandAllBuildConfigurations;FilterBuildConfiguration" />
<!-- Runs in a leaf project (eg: csproj) to determine all configurations -->
<Target Name="GetBuildConfigurations"
Returns="$(_AllBuildConfigurations)">
<PropertyGroup>
<_AllBuildConfigurations>$(BuildConfigurations)</_AllBuildConfigurations>
<_AllBuildConfigurations Condition="'$(BuildConfigurations)' == ''">$(_traversalBuildConfigurations)</_AllBuildConfigurations>
</PropertyGroup>
<!-- Filter out configurations for things not in netcoreapp when building only netcoreapp -->
<PropertyGroup Condition="'$(BuildNETCoreAppOnly)' == 'true' and ('$(MSBuildProjectExtension)' == '.csproj' or '$(MSBuildProjectExtension)' == '.ilproj')">
<PartOfNETCoreAppBuild Condition="'$(PartOfNETCoreAppBuild)' == ''">$(IsNETCoreApp)</PartOfNETCoreAppBuild>
<_AllBuildConfigurations Condition="'$(PartOfNETCoreAppBuild)' != 'true'"></_AllBuildConfigurations>
</PropertyGroup>
</Target>
<!-- Runs in a leaf project (eg: csproj) to determine configurations to package -->
<Target Name="GetPackageConfigurations"
Returns="$(PackageConfigurations)">
<ItemGroup Condition="'$(PackageConfigurations)' == ''">
<_buildConfigurations Include="$(BuildConfigurations)" />
<_excludeBuildConfigurations Include="@(_buildConfigurations)" Condition="'$(IsReferenceAssembly)' == 'true' AND ('%(Identity)' == 'netfx' OR $([System.String]::new('%(Identity)').StartsWith('net4'))) AND '$(IncludeDesktopRefInPackage)' != 'true'"/>
<_excludeBuildConfigurations Include="mono" />
<_packageConfigurations Include="@(_buildConfigurations)" Exclude="@(_excludeBuildConfigurations)" />
</ItemGroup>
<PropertyGroup Condition="'$(PackageConfigurations)' == ''">
<PackageConfigurations>@(_packageConfigurations)</PackageConfigurations>
</PropertyGroup>
</Target>
<!-- Runs in a leaf project (csproj) to determine best configuration for ProjectReferences -->
<Target Name="AnnotateProjectReference"
BeforeTargets="AssignProjectConfiguration"
Condition="'@(ProjectReference)' != ''"
Inputs="%(ProjectReference.Identity)"
Outputs="unused">
<MSBuild Targets="GetBuildConfigurations"
Projects="@(ProjectReference)">
<Output TaskParameter="TargetOutputs" PropertyName="_projectReferenceBuildConfigurations" />
</MSBuild>
<PropertyGroup>
<!--
When building in VS or using the solution file Configuration for some projects is set to Debug/Release
in such cases we should treat it as an empty configuration and set it to be $BuildConfiguration for the
purposes of annotating project references.
-->
<Configuration Condition="'$(Configuration)' == 'Debug' or '$(Configuration)' == 'Release'">$(BuildConfiguration)</Configuration>
</PropertyGroup>
<!-- Find the best configuration for the current Project's Configuration -->
<FindBestConfigurations Properties="@(Property)"
PropertyValues="@(PropertyValue)"
SupportedConfigurations="$(_ProjectReferenceBuildConfigurations)"
Configurations="$(Configuration)">
<Output TaskParameter="BestConfigurations" PropertyName="_projectReferenceConfiguration" />
</FindBestConfigurations>
<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>
<!-- Project references for non-test assemblies should never be copied to the output. -->
<ProjectReference Condition="'$(IsTestProject)' != 'true'">
<Private>false</Private>
</ProjectReference>
</ItemGroup>
</Target>
<Target Name="BuildAllConfigurations">
<ItemGroup>
<_buildConfigurations Include="$(BuildConfigurations)" />
<_buildConfigurations Condition="'@(_buildConfigurations)' == ''" Include="$(_traversalBuildConfigurations)" />
</ItemGroup>
<MSBuild Projects="$(MSBuildProjectFullPath)"
Properties="Configuration=%(_buildConfigurations.Identity);BuildAllConfigurations=true" />
</Target>
</Project>