Skip to content

Commit 035ba44

Browse files
committed
Add more documentation comments to Targets files
1 parent 7b701ca commit 035ba44

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.PackTool.targets

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@ Copyright (c) .NET Foundation. All rights reserved.
1010
***********************************************************************************************
1111
-->
1212

13+
<!--
14+
15+
NOTE: This file is imported from the following contexts, so be aware when writing Conditions and thinking about evaluation order:
16+
* cross-targeting (multi-TFM) builds.
17+
* these may not have a RID or RIDs set, but still need to be able to pack tools
18+
* IsCrossTargetingBuild is set to true in this case
19+
* 'outer' builds for a single TFM
20+
* these builds are RID-agnostic, but still need to be able to pack 'inner', RID-specific tools.
21+
* IsCrossTargetingBuild is unset in this case, RuntimeIdentifier is unset, and RuntimeIdentifiers or ToolPackageRuntimeIdentifiers is set to a list of RIDs
22+
* if these builds are RID-specific but not AOT, then we pack the outer tool without implementation dlls and the N inner-RID-specific tools
23+
* if these builds are RID-specific and AOT, then we pack the outer tool only without implementation dlls
24+
* if these builds are RID-agnostic, then we pack the outer tool only with implementation dlls
25+
* 'inner' builds for a single TFM
26+
* these builds are RID-specific, and have RuntimeIdentifier set to a single RID, and RuntimeIdentifiers or ToolPackageRuntimeIdentifiers set to a list of RIDs
27+
* these builds pack only the inner, RID-specific tool implementation dlls and have a unique PackageType of DotnetToolRidPackage
28+
-->
29+
1330
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
1431
<UsingTask TaskName="Microsoft.NET.Build.Tasks.GenerateToolsSettingsFile"
1532
AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" />
@@ -23,13 +40,16 @@ Copyright (c) .NET Foundation. All rights reserved.
2340
<PropertyGroup>
2441
<!-- tools are specially-formatted packages, so we tell nuget Pack to not even try to include build output -->
2542
<IncludeBuildOutput>false</IncludeBuildOutput>
43+
2644
<!-- the publish* properties _can_ be set, but only for the 'inner' RID-specific builds. We need to make sure that for the outer, agnostic build they are unset -->
2745
<PublishSelfContained Condition="'$(RuntimeIdentifier)' == ''">false</PublishSelfContained>
2846
<!-- Have to set SelfContained similarly because PackTool targets are imported _after_ RuntimeIdentifierInference targets, where the Publish* properties are
2947
forwarded to the 'base' properties. -->
3048
<SelfContained Condition="'$(RuntimeIdentifier)' == ''">false</SelfContained>
3149
<PublishTrimmed Condition="'$(RuntimeIdentifier)' == ''">false</PublishTrimmed>
3250
<PublishReadyToRun Condition="'$(RuntimeIdentifier)' == ''">false</PublishReadyToRun>
51+
<!-- We need to know if the inner builds are _intended_ to be AOT even if we then explicitly disable AOT for the outer builds.
52+
Knowing this lets us correctly decide to create the RID-specific inner tools or not when packaging the outer tool. -->
3353
<_InnerToolsPublishAot>false</_InnerToolsPublishAot>
3454
<_InnerToolsPublishAot Condition="'$(RuntimeIdentifier)' == '' and '$(PublishAot)' == 'true'">true</_InnerToolsPublishAot>
3555
<PublishAot Condition="'$(RuntimeIdentifier)' == ''">false</PublishAot>
@@ -39,20 +59,22 @@ Copyright (c) .NET Foundation. All rights reserved.
3959
<!-- we want to ensure that we _do_ publish any AppHosts for the 'inner', RID-specific builds -->
4060
<UseAppHost Condition="'$(RuntimeIdentifier)' != ''">true</UseAppHost>
4161

42-
<!-- If shims are included, we need to make sure we restore for those RIDs so the apphost shims are available during restore/publish -->
62+
<!-- If shims are included, we need to make sure we restore for those RIDs so the apphost shims are available during restore/publish.
63+
This means that we need to set RuntimeIdentifiers. However we need to track certain information about the _users_ decisions around RIDs
64+
so that we can correctly decide if we need to package RID-specific tools or not. -->
4365
<_ToolRidsAreOnlyShims>false</_ToolRidsAreOnlyShims>
4466
<_ToolRidsAreOnlyShims Condition="'$(RuntimeIdentifiers)' == '' and $(PackAsToolShimRuntimeIdentifiers) != '' ">true</_ToolRidsAreOnlyShims>
4567
<_UserSpecifiedToolPackageRids Condition="'$(ToolPackageRuntimeIdentifiers)' != ''">$(ToolPackageRuntimeIdentifiers)</_UserSpecifiedToolPackageRids>
4668
<_UserSpecifiedToolPackageRids Condition="'$(_UserSpecifiedToolPackageRids)' == ''">$(RuntimeIdentifiers)</_UserSpecifiedToolPackageRids>
69+
<_HasRIDSpecificTools Condition=" '$(_UserSpecifiedToolPackageRids)' != '' ">true</_HasRIDSpecificTools>
70+
<_HasRIDSpecificTools Condition="'$(_HasRIDSpecificTools)' == ''">false</_HasRIDSpecificTools>
4771
<RuntimeIdentifiers Condition="'$(PackAsToolShimRuntimeIdentifiers)' != ''">$(_UserSpecifiedToolPackageRids);$(PackAsToolShimRuntimeIdentifiers)</RuntimeIdentifiers>
4872

4973
<!-- Tool implementation files are not included in the primary package when the tool has RID-specific packages. So only pack the tool implementation
5074
(and only depend on publish) if there are no RID-specific packages, or if the RuntimeIdentifier is set. -->
5175
<_ToolPackageShouldIncludeImplementation Condition=" '$(PackAsTool)' == 'true' And
5276
('$(_UserSpecifiedToolPackageRids)' == '' Or '$(RuntimeIdentifier)' != '')">true</_ToolPackageShouldIncludeImplementation>
5377
<_ToolPackageShouldIncludeImplementation Condition="'$(_ToolPackageShouldIncludeImplementation)' == ''">false</_ToolPackageShouldIncludeImplementation>
54-
<_HasRIDSpecificTools Condition=" '$(_UserSpecifiedToolPackageRids)' != '' ">true</_HasRIDSpecificTools>
55-
<_HasRIDSpecificTools Condition="'$(_HasRIDSpecificTools)' == ''">false</_HasRIDSpecificTools>
5678

5779
<!-- inner builds and non-RID-specific outer builds need publish content-->
5880
<_PackToolPublishDependency Condition=" '$(_ToolPackageShouldIncludeImplementation)' != '' and '$(GeneratePackageOnBuild)' != 'true' and $(IsPublishable) == 'true' ">Publish</_PackToolPublishDependency>
@@ -61,10 +83,16 @@ Copyright (c) .NET Foundation. All rights reserved.
6183
dependencies of the no-build Publish Target, _PublishNoBuildAlternative -->
6284
<_PackToolPublishDependency Condition=" '$(_ToolPackageShouldIncludeImplementation)' != '' and '$(GeneratePackageOnBuild)' == 'true' and $(IsPublishable) == 'true' ">$(_PublishNoBuildAlternativeDependsOn)</_PackToolPublishDependency>
6385

64-
<!-- Trigger RID-specific inner builds if RID-specific mode is enabled-->
86+
<!-- GenerateNuspec is called in two places: crossTargeting NuGet targets, and single-targeting NuGet targets.
87+
Tools need to ensure that
88+
a) they can set the correct PackageType(s) and
89+
b) we can create the necessary inner-RID packages
90+
regardless of which way we are invoked. This means that these key entry points need to be callable from both GenerateNuspec methods.
91+
This also means that we need to set correct Conditions on the Targets themselves so they don't run if they aren't actually necessary. -->
6592
<GenerateNuspecDependsOn>$(GenerateNuspecDependsOn);SetDotnetToolPackageType;_CreateRIDSpecificToolPackages</GenerateNuspecDependsOn>
6693

67-
<!-- finally set up the entrypoint for all tool-content regardless of tool type-->
94+
<!-- Finally set up the entrypoint for all tool-content regardless of tool type. This doesn't get set as a GenerateNuspecDependsOn
95+
Because this target is inherently TFM-specific, and NuGet handles invoking this target once per TFM as part of the packaging process. -->
6896
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);PackTool</TargetsForTfmSpecificContentInPackage>
6997
</PropertyGroup>
7098
<!--
@@ -353,7 +381,8 @@ Copyright (c) .NET Foundation. All rights reserved.
353381

354382
</Target>
355383

356-
<!-- orchestrator for making the N RID-specific tool packages -->
384+
<!-- Orchestrator for making the N RID-specific tool packages if this Tool supports that mode.
385+
We can't call this for AOT'd tools because we can't AOT cross-architecture and cross-platform in .NET today. -->
357386
<Target Name="_CreateRIDSpecificToolPackages" Condition="'$(RuntimeIdentifier)' == '' and $(_HasRIDSpecificTools) and !$(_InnerToolsPublishAot) and !$(_ToolPackageShouldIncludeImplementation)">
358387
<PropertyGroup>
359388
<_PackageRids>$(ToolPackageRuntimeIdentifiers)</_PackageRids>

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.CrossTargeting.targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Copyright (c) .NET Foundation. All rights reserved.
1313

1414
<Import Project="Microsoft.NET.Sdk.Common.targets"/>
1515
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.Sdk.SourceLink.targets" Condition="'$(SuppressImplicitGitSourceLink)' != 'true'"/>
16+
<!-- Importing the PackTool targets because tools that have TargetFrameworks set still need a couple key targets
17+
in order to package correctly, like the ones that add the DotnetTool PackageType. -->
1618
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.PackTool.targets" Condition="'$(PackAsTool)' == 'true'" />
1719

1820
<!--

0 commit comments

Comments
 (0)