-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Microsoft.Common.CrossTargeting.targets
249 lines (199 loc) · 13.2 KB
/
Microsoft.Common.CrossTargeting.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<!--
***********************************************************************************************
Microsoft.Common.CrossTargeting.targets
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
created a backup copy. Incorrect changes to this file will make it
impossible to load or build your projects from the command-line or the IDE.
Copyright (C) Microsoft Corporation. All rights reserved.
***********************************************************************************************
-->
<Project DefaultTargets="Build">
<PropertyGroup>
<BuildInParallel Condition="'$(BuildInParallel)' == ''">true</BuildInParallel>
<ImportByWildcardBeforeMicrosoftCommonCrossTargetingTargets Condition="'$(ImportByWildcardBeforeMicrosoftCommonCrossTargetingTargets)' == ''">true</ImportByWildcardBeforeMicrosoftCommonCrossTargetingTargets>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.CrossTargeting.targets\ImportBefore\*.targets"
Condition="'$(ImportByWildcardBeforeMicrosoftCommonCrossTargetingTargets)' == 'true' and exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.CrossTargeting.targets\ImportBefore')"/>
<Import Project="$(CustomBeforeMicrosoftCommonCrossTargetingTargets)" Condition="'$(CustomBeforeMicrosoftCommonCrossTargetingTargets)' != '' and Exists('$(CustomBeforeMicrosoftCommonCrossTargetingTargets)')"/>
<Target Name="GetTargetFrameworks"
DependsOnTargets="GetTargetFrameworksWithPlatformFromInnerBuilds"
Returns="@(_ThisProjectBuildMetadata)">
<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>
<IsRidAgnostic>@(_TargetFrameworkInfo->'%(IsRidAgnostic)')</IsRidAgnostic>
<!-- Extract necessary information for SetPlatform negotiation -->
<!-- This target does not run for cpp projects. -->
<IsVcxOrNativeProj>false</IsVcxOrNativeProj>
<Platform Condition="$([MSBuild]::AreFeaturesEnabled('17.4'))">$(Platform)</Platform>
<Platforms>$(Platforms)</Platforms>
</_ThisProjectBuildMetadata>
</ItemGroup>
</Target>
<Target Name="_ComputeTargetFrameworkItems" Returns="@(InnerOutput)">
<ItemGroup>
<_TargetFramework Include="$(TargetFrameworks)" />
<!-- Make normalization explicit: Trim; Deduplicate by keeping first occurrence, case insensitive -->
<_TargetFrameworkNormalized Include="@(_TargetFramework->Trim()->Distinct())" />
<_InnerBuildProjects Include="$(MSBuildProjectFile)">
<AdditionalProperties>TargetFramework=%(_TargetFrameworkNormalized.Identity)</AdditionalProperties>
</_InnerBuildProjects>
</ItemGroup>
</Target>
<Target Name="GetTargetFrameworksWithPlatformFromInnerBuilds"
DependsOnTargets="_ComputeTargetFrameworkItems">
<MSBuild Projects="@(_InnerBuildProjects)"
Condition="'@(_InnerBuildProjects)' != '' "
Targets="GetTargetFrameworksWithPlatformForSingleTargetFramework"
BuildInParallel="$(BuildInParallel)">
<Output ItemName="_TargetFrameworkInfo" TaskParameter="TargetOutputs" />
</MSBuild>
</Target>
<!--
Target that allows targets consuming source control confirmation to establish a dependency on targets producing this information.
Any target that reads SourceRevisionId, PrivateRepositoryUrl, SourceRoot, and other source control properties and items
should depend on this target and be conditioned on '$(SourceControlInformationFeatureSupported)' == 'true'.
SourceRevisionId property uniquely identifies the source control revision of the repository the project belongs to.
For Git repositories this id is a commit hash, for TFVC repositories it's the changeset number, etc.
PrivateRepositoryUrl property stores the URL of the repository supplied by the CI server or retrieved from source control manager.
Targets consuming this property shall not publish its value implicitly as it might inadvertently reveal an internal URL.
Instead, they shall only do so if the project sets PublishRepositoryUrl property to true. For example, the NuGet Pack target
may include the repository URL in the nuspec file generated for NuGet package produced by the project if PublishRepositoryUrl is true.
SourceRoot item group lists all source roots that the project source files reside under and their mapping to source control server URLs,
if available. This includes both source files under source control as well as source files in source packages. SourceRoot items are
used by compilers to determine path map in deterministic build and by SourceLink provider, which maps local paths to URLs of source files
stored on the source control server.
Source control information provider that sets these properties and items shall execute before this target (by including
InitializeSourceControlInformation in its BeforeTargets) and set source control properties and items that haven't been initialized yet.
-->
<Target Name="InitializeSourceControlInformation" />
<PropertyGroup>
<SourceControlInformationFeatureSupported>true</SourceControlInformationFeatureSupported>
</PropertyGroup>
<!--
============================================================
DispatchToInnerBuilds
Builds this project with /t:$(InnerTarget) /p:TargetFramework=X for each
value X in $(TargetFrameworks)
[IN]
$(TargetFrameworks) - Semicolon delimited list of target frameworks.
$(InnerTargets) - The targets to build for each target framework
[OUT]
@(InnerOutput) - The combined output items of the inner targets across
all target frameworks..
============================================================
-->
<Target Name="DispatchToInnerBuilds"
DependsOnTargets="_ComputeTargetFrameworkItems"
Returns="@(InnerOutput)">
<!-- If this logic is changed, also update Clean -->
<MSBuild Projects="@(_InnerBuildProjects)"
Condition="'@(_InnerBuildProjects)' != '' "
Targets="$(InnerTargets)"
BuildInParallel="$(BuildInParallel)">
<Output ItemName="InnerOutput" TaskParameter="TargetOutputs" />
</MSBuild>
</Target>
<!--
============================================================
Build
Cross-targeting version of Build.
[IN]
$(TargetFrameworks) - Semicolon delimited list of target frameworks.
$(InnerTargets) - The targets to build for each target framework. Defaults
to 'Build' if unset, but allows override to support
`msbuild /p:InnerTargets=X;Y;Z` which will build X, Y,
and Z targets for each target framework.
[OUT]
@(InnerOutput) - The combined output items of the inner targets across
all builds.
============================================================
-->
<Target Name="Build" DependsOnTargets="_SetBuildInnerTarget;DispatchToInnerBuilds" />
<Target Name="_SetBuildInnerTarget" Returns="@(InnerOutput)">
<PropertyGroup Condition="'$(InnerTargets)' == ''">
<InnerTargets>Build</InnerTargets>
</PropertyGroup>
</Target>
<!--
============================================================
Clean
Cross-targeting version of clean.
Inner-build dispatch is a clone of DispatchToInnerBuilds;
the only reason it's replicated is that it must be a different
target to be run in the same build (e.g. by Rebuild or by
a /t:Clean;Build invocation.
============================================================
-->
<Target Name="Clean"
DependsOnTargets="_ComputeTargetFrameworkItems">
<!-- If this logic is changed, also update DispatchToInnerBuilds -->
<MSBuild Projects="@(_InnerBuildProjects)"
Condition="'@(_InnerBuildProjects)' != '' "
Targets="Clean"
BuildInParallel="$(BuildInParallel)" />
</Target>
<!--
============================================================
Rebuild
Cross-targeting version of rebuild.
============================================================
-->
<Target Name="Rebuild" DependsOnTargets="Clean;Build" />
<!--
This will import NuGet restore targets. We need restore to work before any package assets are available.
-->
<PropertyGroup>
<MSBuildUseVisualStudioDirectoryLayout Condition="'$(MSBuildUseVisualStudioDirectoryLayout)'==''">$([MSBuild]::IsRunningFromVisualStudio())</MSBuildUseVisualStudioDirectoryLayout>
<NuGetRestoreTargets Condition="'$(NuGetRestoreTargets)'=='' and '$(MSBuildUseVisualStudioDirectoryLayout)'=='true'">$([MSBuild]::GetToolsDirectory32())\..\..\..\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.targets</NuGetRestoreTargets>
<NuGetRestoreTargets Condition="'$(NuGetRestoreTargets)'==''">$(MSBuildToolsPath)\NuGet.targets</NuGetRestoreTargets>
</PropertyGroup>
<Import Project="$(NuGetRestoreTargets)" />
<Import Project="$(CustomAfterMicrosoftCommonCrossTargetingTargets)" Condition="'$(CustomAfterMicrosoftCommonCrossTargetingTargets)' != '' and Exists('$(CustomAfterMicrosoftCommonCrossTargetingTargets)')"/>
<!--
Allow extensions like NuGet restore to work before any package assets are available.
-->
<PropertyGroup>
<ImportByWildcardAfterMicrosoftCommonCrossTargetingTargets Condition="'$(ImportByWildcardAfterMicrosoftCommonCrossTargetingTargets)' == ''">true</ImportByWildcardAfterMicrosoftCommonCrossTargetingTargets>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.CrossTargeting.targets\ImportAfter\*.targets"
Condition="'$(ImportByWildcardAfterMicrosoftCommonCrossTargetingTargets)' == 'true' and exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.CrossTargeting.targets\ImportAfter')"/>
<!--
Import project extensions which usually come from packages. Package management systems will create a file at:
$(MSBuildProjectExtensionsPath)\$(MSBuildProjectFile).<SomethingUnique>.targets
Each package management system should use a unique moniker to avoid collisions. It is a wild-card iport so the package
management system can write out multiple files but the order of the import is alphabetic because MSBuild sorts the list.
This is the same import that would happen in an inner (non-cross targeting) build. Package management systems are responsible for generating
appropriate conditions based on $(IsCrossTargetingBuild) to pull in only those package targets that are meant to participate in a cross-targeting
build.
-->
<PropertyGroup>
<ImportProjectExtensionTargets Condition="'$(ImportProjectExtensionTargets)' == ''">true</ImportProjectExtensionTargets>
</PropertyGroup>
<Import Project="$(MSBuildProjectExtensionsPath)$(MSBuildProjectFile).*.targets" Condition="'$(ImportProjectExtensionTargets)' == 'true' and exists('$(MSBuildProjectExtensionsPath)')" />
<PropertyGroup>
<ImportDirectoryBuildTargets Condition="'$(ImportDirectoryBuildTargets)' == ''">true</ImportDirectoryBuildTargets>
</PropertyGroup>
<!--
Determine the path to the directory build targets file if the user did not disable $(ImportDirectoryBuildTargets) and
they did not already specify an absolute path to use via $(DirectoryBuildTargetsPath)
-->
<PropertyGroup Condition="'$(ImportDirectoryBuildTargets)' == 'true' and '$(DirectoryBuildTargetsPath)' == ''">
<_DirectoryBuildTargetsFile Condition="'$(_DirectoryBuildTargetsFile)' == ''">Directory.Build.targets</_DirectoryBuildTargetsFile>
<_DirectoryBuildTargetsBasePath Condition="'$(_DirectoryBuildTargetsBasePath)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), '$(_DirectoryBuildTargetsFile)'))</_DirectoryBuildTargetsBasePath>
<DirectoryBuildTargetsPath Condition="'$(_DirectoryBuildTargetsBasePath)' != '' and '$(_DirectoryBuildTargetsFile)' != ''">$([System.IO.Path]::Combine('$(_DirectoryBuildTargetsBasePath)', '$(_DirectoryBuildTargetsFile)'))</DirectoryBuildTargetsPath>
</PropertyGroup>
<Import Project="$(DirectoryBuildTargetsPath)" Condition="'$(ImportDirectoryBuildTargets)' == 'true' and exists('$(DirectoryBuildTargetsPath)')"/>
</Project>