2 ***********************************************************************************************
3 Microsoft.Common.CrossTargeting.targets
5 WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
6 created a backup copy. Incorrect changes to this file will make it
7 impossible to load or build your projects from the command-line or the IDE.
9 Copyright (C) Microsoft Corporation. All rights reserved.
10 ***********************************************************************************************
13 <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
15 <BuildInParallel Condition="'$(BuildInParallel)' == ''">true</BuildInParallel>
16 <ImportByWildcardBeforeMicrosoftCommonCrossTargetingTargets Condition="'$(ImportByWildcardBeforeMicrosoftCommonCrossTargetingTargets)' == ''">true</ImportByWildcardBeforeMicrosoftCommonCrossTargetingTargets>
18 <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.CrossTargeting.targets\ImportBefore\*.targets"
19 Condition="'$(ImportByWildcardBeforeMicrosoftCommonCrossTargetingTargets)' == 'true' and exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.CrossTargeting.targets\ImportBefore')"/>
21 <Import Project="$(CustomBeforeMicrosoftCommonCrossTargetingTargets)" Condition="'$(CustomBeforeMicrosoftCommonCrossTargetingTargets)' != '' and Exists('$(CustomBeforeMicrosoftCommonCrossTargetingTargets)')"/>
23 <Target Name="_ComputeTargetFrameworkItems" Returns="@(InnerOutput)">
25 <_TargetFramework Include="$(TargetFrameworks)" />
26 <_InnerBuildProjects Include="$(MSBuildProjectFile)">
27 <AdditionalProperties>TargetFramework=%(_TargetFramework.Identity)</AdditionalProperties>
28 </_InnerBuildProjects>
33 ============================================================
36 Builds this project with /t:$(InnerTarget) /p:TargetFramework=X for each
37 value X in $(TargetFrameworks)
40 $(TargetFrameworks) - Semicolon delimited list of target frameworks.
41 $(InnerTargets) - The targets to build for each target framework
44 @(InnerOutput) - The combined output items of the inner targets across
45 all target frameworks..
46 ============================================================
48 <Target Name="DispatchToInnerBuilds"
49 DependsOnTargets="_ComputeTargetFrameworkItems"
50 Returns="@(InnerOutput)">
51 <!-- If this logic is changed, also update Clean -->
52 <MSBuild Projects="@(_InnerBuildProjects)"
53 Condition="'@(_InnerBuildProjects)' != '' "
54 Targets="$(InnerTargets)"
55 BuildInParallel="$(BuildInParallel)">
56 <Output ItemName="InnerOutput" TaskParameter="TargetOutputs" />
61 ============================================================
64 Cross-targeting version of Build.
67 $(TargetFrameworks) - Semicolon delimited list of target frameworks.
69 $(InnerTargets) - The targets to build for each target framework. Defaults
70 to 'Build' if unset, but allows override to support
71 `msbuild /p:InnerTargets=X;Y;Z` which will build X, Y,
72 and Z targets for each target framework.
75 @(InnerOutput) - The combined output items of the inner targets across
77 ============================================================
79 <Target Name="Build" DependsOnTargets="_SetBuildInnerTarget;DispatchToInnerBuilds" />
81 <Target Name="_SetBuildInnerTarget" Returns="@(InnerOutput)">
82 <PropertyGroup Condition="'$(InnerTargets)' == ''">
83 <InnerTargets>Build</InnerTargets>
89 ============================================================
92 Cross-targeting version of clean.
94 Inner-build dispatch is a clone of DispatchToInnerBuilds;
95 the only reason it's replicated is that it must be a different
96 target to be run in the same build (e.g. by Rebuild or by
97 a /t:Clean;Build invocation.
98 ============================================================
101 DependsOnTargets="_ComputeTargetFrameworkItems">
102 <!-- If this logic is changed, also update DispatchToInnerBuilds -->
103 <MSBuild Projects="@(_InnerBuildProjects)"
104 Condition="'@(_InnerBuildProjects)' != '' "
106 BuildInParallel="$(BuildInParallel)" />
110 ============================================================
113 Cross-targeting version of rebuild.
114 ============================================================
116 <Target Name="Rebuild" DependsOnTargets="Clean;Build" />
119 This will import NuGet restore targets, which is a special case separate from the package -> project extension
120 mechanism below. For obvious reasons, we need restore to work before any package assets are available.
122 TODO: https://github.com/Microsoft/msbuild/issues/1061: This is now generalized with less coupling to nuget,
123 but this codepath should remain as a compat shim until NuGet and the CLI use the CrossTargeting imports.
126 <ImportByWildcardAfterMicrosoftCommonTargets Condition="'$(ImportByWildcardAfterMicrosoftCommonTargets)' == ''">true</ImportByWildcardAfterMicrosoftCommonTargets>
128 <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.targets\ImportAfter\*.NuGet.*.targets"
129 Condition="'$(ImportByWildcardAfterMicrosoftCommonTargets)' == 'true' and exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.targets\ImportAfter')"/>
131 <Import Project="$(CustomAfterMicrosoftCommonCrossTargetingTargets)" Condition="'$(CustomAfterMicrosoftCommonCrossTargetingTargets)' != '' and Exists('$(CustomAfterMicrosoftCommonCrossTargetingTargets)')"/>
134 Allow extensions like NuGet restore to work before any package assets are available.
137 <ImportByWildcardAfterMicrosoftCommonCrossTargetingTargets Condition="'$(ImportByWildcardAfterMicrosoftCommonCrossTargetingTargets)' == ''">true</ImportByWildcardAfterMicrosoftCommonCrossTargetingTargets>
139 <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.CrossTargeting.targets\ImportAfter\*.targets"
140 Condition="'$(ImportByWildcardAfterMicrosoftCommonCrossTargetingTargets)' == 'true' and exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.CrossTargeting.targets\ImportAfter')"/>
143 Import project extensions which usually come from packages. Package management systems will create a file at:
144 $(MSBuildProjectExtensionsPath)\$(MSBuildProjectFile).<SomethingUnique>.targets
146 Each package management system should use a unique moniker to avoid collisions. It is a wild-card iport so the package
147 management system can write out multiple files but the order of the import is alphabetic because MSBuild sorts the list.
149 This is the same import that would happen in an inner (non-cross targeting) build. Package management systems are responsible for generating
150 appropriate conditions based on $(IsCrossTargetingBuild) to pull in only those package targets that are meant to participate in a cross-targeting
154 <ImportProjectExtensionTargets Condition="'$(ImportProjectExtensionTargets)' == ''">true</ImportProjectExtensionTargets>
157 <Import Project="$(MSBuildProjectExtensionsPath)$(MSBuildProjectFile).*.targets" Condition="'$(ImportProjectExtensionTargets)' == 'true' and exists('$(MSBuildProjectExtensionsPath)')" />
160 <ImportDirectoryBuildTargets Condition="'$(ImportDirectoryBuildTargets)' == ''">true</ImportDirectoryBuildTargets>
164 Determine the path to the directory build targets file if the user did not disable $(ImportDirectoryBuildTargets) and
165 they did not already specify an absolute path to use via $(DirectoryBuildTargetsPath)
167 <PropertyGroup Condition="'$(ImportDirectoryBuildTargets)' == 'true' and '$(DirectoryBuildTargetsPath)' == ''">
168 <_DirectoryBuildTargetsFile Condition="'$(_DirectoryBuildTargetsFile)' == ''">Directory.Build.targets</_DirectoryBuildTargetsFile>
169 <_DirectoryBuildTargetsBasePath Condition="'$(_DirectoryBuildTargetsBasePath)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), '$(_DirectoryBuildTargetsFile)'))</_DirectoryBuildTargetsBasePath>
170 <DirectoryBuildTargetsPath Condition="'$(_DirectoryBuildTargetsBasePath)' != '' and '$(_DirectoryBuildTargetsFile)' != ''">$([System.IO.Path]::Combine('$(_DirectoryBuildTargetsBasePath)', '$(_DirectoryBuildTargetsFile)'))</DirectoryBuildTargetsPath>
173 <PropertyGroup Condition="'$(ImportDirectoryBuildTargets)' == 'true' and exists('$(DirectoryBuildTargetsPath)')">
174 <MSBuildAllProjects>$(MSBuildAllProjects);$(DirectoryBuildTargetsPath)</MSBuildAllProjects>
177 <Import Project="$(DirectoryBuildTargetsPath)" Condition="'$(ImportDirectoryBuildTargets)' == 'true' and exists('$(DirectoryBuildTargetsPath)')"/>
179 <!-- TODO: https://github.com/Microsoft/msbuild/issues/1062: Remove this temporary hook when possible. -->
180 <Import Project="$(CoreCrossTargetingTargetsPath)"
181 Condition="'$(CoreCrossTargetingTargetsPath)' != '' and Exists('$(CoreCrossTargetingTargetsPath)')" />