Skip to content

Commit c70bf75

Browse files
committed
make tool packages publish instead of build
1 parent 06fa327 commit c70bf75

File tree

1 file changed

+15
-40
lines changed

1 file changed

+15
-40
lines changed

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

Lines changed: 15 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ Copyright (c) .NET Foundation. All rights reserved.
2424
<UsingTask TaskName="Microsoft.NET.Build.Tasks.RemoveTargetFromList"
2525
AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" />
2626

27+
<PropertyGroup>
28+
<!-- tools are specially-formatted packages, so we tell nuget Pack to not even try to include build output -->
29+
<IncludeBuildOutput>false</IncludeBuildOutput>
30+
<!-- 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 -->
31+
<PublishSelfContained Condition="'$(RuntimeIdentifier)' == ''">false</PublishSelfContained>
32+
<PublishTrimmed Condition="'$(RuntimeIdentifier)' == ''">false</PublishTrimmed>
33+
<PublishReadyToRun Condition="'$(RuntimeIdentifier)' == ''">false</PublishReadyToRun>
34+
<PublishAot Condition="'$(RuntimeIdentifier)' == ''">false</PublishAot>
35+
</PropertyGroup>
2736
<!--
2837
2938
TODO:
@@ -32,40 +41,15 @@ Copyright (c) .NET Foundation. All rights reserved.
3241
- Consider a way of declaring what RID a RID-specific package is for, besides just the convention in the package ID
3342
-->
3443

35-
3644
<!--
3745
Mark all dependency as private assets. But keep them as Publish. So dependency DLLs will be included in NuGet package, while
3846
there is no dependency in nuspec. And add Microsoft.NETCore.Platforms, which is used to select correct RID assets.
3947
-->
4048
<PropertyGroup>
4149
<_ToolsSettingsFilePath>$(IntermediateOutputPath)DotnetToolSettings.xml</_ToolsSettingsFilePath>
4250
<SuppressDependenciesWhenPacking Condition=" '$(PackAsTool)' == 'true' ">true</SuppressDependenciesWhenPacking>
43-
4451
</PropertyGroup>
4552

46-
<Target Name="PackAsToolSwitchToNoBuild"
47-
BeforeTargets="_IntermediatePack"
48-
Condition=" '$(PackAsTool)' == 'true' And
49-
'@(ToolPackageRuntimeIdentifier)' != '' And
50-
'$(RuntimeIdentifier)' == ''">
51-
52-
<!-- If we are building the primary package for a tool with RID-specific packages, we don't include any of the build output in the package, so we don't need to run Build.
53-
We might not be able to build without a RuntimeIdentifier if PublishAOT or SelfContained is set to true, so we skip the build so it doesn't fail.
54-
55-
We use a task to remove the Build target from GenerateNuspecDependsOn. This is effectively what happens if NoBuild is set, but we can't use the same logic because
56-
we need to look at items (ToolPackageRuntimeIdentifier) to determine if we are building the primary package for a tool with RID-specific packages. So we have to fix
57-
up the dependency list afterwards.
58-
59-
We also can't use MSBuild property functions for string replacement to remove Build from the list, because MSBuild will escape the semicolons as %3B, and there
60-
doesn't seem to be a way of avoiding that without using a task.
61-
-->
62-
<RemoveTargetFromList TargetList="$(GenerateNuspecDependsOn)"
63-
TargetToRemove="Build">
64-
<Output TaskParameter="UpdatedTargetList" PropertyName="GenerateNuspecDependsOn" />
65-
</RemoveTargetFromList>
66-
67-
</Target>
68-
6953
<!--
7054
PackageId must be set before:
7155
- _GenerateRestoreProjectSpec -> _GetRestoreSettings
@@ -75,18 +59,9 @@ Copyright (c) .NET Foundation. All rights reserved.
7559
-->
7660
<Target Name="SetPackToolProperties"
7761
BeforeTargets="_GenerateRestoreProjectSpec;_GenerateToolsSettingsFileInputCache;_GenerateShimInputCache;_GetOutputItemsFromPack">
78-
79-
<!-- Tool implementation files are not included in the primary package when the tool has RID-specific packages. So only pack the tool implementation
80-
(and only depend on publish) if there are no RID-specific packages, or if the RuntimeIdentifier is set. -->
81-
<PropertyGroup Condition="'$(_ToolPackageShouldIncludeImplementation)' == ''">
82-
<_ToolPackageShouldIncludeImplementation Condition=" '$(PackAsTool)' == 'true' And
83-
('@(ToolPackageRuntimeIdentifier)' == '' Or '$(RuntimeIdentifier)' != '')">true</_ToolPackageShouldIncludeImplementation>
84-
<_ToolPackageShouldIncludeImplementation Condition="'$(_ToolPackageShouldIncludeImplementation)' == ''">false</_ToolPackageShouldIncludeImplementation>
85-
</PropertyGroup>
86-
87-
<PropertyGroup Condition="'$(_ToolPackageShouldIncludeImplementation)' == 'true'">
88-
<_PackToolPublishDependency Condition=" ('$(GeneratePackageOnBuild)' != 'true' and '$(NoBuild)' != 'true') and $(IsPublishable) == 'true' ">_PublishBuildAlternative</_PackToolPublishDependency>
89-
<_PackToolPublishDependency Condition=" ('$(GeneratePackageOnBuild)' == 'true' or '$(NoBuild)' == 'true') and $(IsPublishable) == 'true' ">$(_PublishNoBuildAlternativeDependsOn)</_PackToolPublishDependency>
62+
<PropertyGroup>
63+
<GenerateNuspecDependsOn Condition=" ('$(GeneratePackageOnBuild)' != 'true' and '$(NoBuild)' != 'true') and $(IsPublishable) == 'true' ">$(GenerateNuspecDependsOn);_PublishBuildAlternative</GenerateNuspecDependsOn>
64+
<GenerateNuspecDependsOn Condition=" ('$(GeneratePackageOnBuild)' == 'true' or '$(NoBuild)' == 'true') and $(IsPublishable) == 'true' ">$(GenerateNuspecDependsOn);$(_PublishNoBuildAlternativeDependsOn)</GenerateNuspecDependsOn>
9065
</PropertyGroup>
9166

9267
<!-- Needs to be in a target so we don't need to worry about evaluation order with NativeBinary property -->
@@ -102,19 +77,19 @@ Copyright (c) .NET Foundation. All rights reserved.
10277

10378
</Target>
10479

105-
<Target Name="PackToolImplementation" Condition="'$(_ToolPackageShouldIncludeImplementation)' == 'true'">
80+
<Target Name="PackToolImplementation">
10681

10782
<ItemGroup>
10883
<_GeneratedFiles Include="$(PublishDepsFilePath)" Condition="'$(GenerateDependencyFile)' != 'true' or '$(_UseBuildDependencyFile)' == 'true'" />
10984
<_GeneratedFiles Include="$(PublishRuntimeConfigFilePath)"/>
11085
</ItemGroup>
111-
86+
11287
</Target>
11388

11489
<!-- This indirection target essentially allows one target dependency (SetPackToolProperties) of PackTool modify the dependencies of PackTool. -->
11590
<Target Name="PackToPublishDependencyIndirection"
11691
DependsOnTargets="$(_PackToolPublishDependency)"/>
117-
92+
11893
<Target Name="PackTool" DependsOnTargets="SetPackToolProperties;GenerateToolsSettingsFileFromBuildProperty;PackToPublishDependencyIndirection;_PackToolValidation;PackToolImplementation" Condition=" '$(PackAsTool)' == 'true' ">
11994
<ItemGroup>
12095
<_GeneratedFiles Include="$(_ToolsSettingsFilePath)"/>

0 commit comments

Comments
 (0)