Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit 871d3ea

Browse files
committed
Don't depend on built-in targets assigning and copying
Make the NuGetizer targets more self-contained by using its own item groups synthesized from @(Content) and @(None), leveraging the same AssignTargetPath built-in target that the common targets use, for consistency. This simplifies the conditions in the inference target quite a bit as a bonus.
1 parent e0aac12 commit 871d3ea

2 files changed

Lines changed: 36 additions & 44 deletions

File tree

src/Build/NuGet.Build.Packaging.Tasks/NuGet.Build.Packaging.Inference.targets

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,21 @@ Copyright (c) .NET Foundation. All rights reserved.
5050
<PrimaryOutputFrameworkSpecific>@(_PrimaryOutputKind)</PrimaryOutputFrameworkSpecific>
5151
</PropertyGroup>
5252

53+
<!-- Ensure TargetPath -->
54+
<AssignTargetPath Files="@(Content)" RootFolder="$(MSBuildProjectDirectory)"
55+
Condition="'%(Content.Pack)' == 'true' or
56+
'%(Content.Kind)' != '' or
57+
('$(IncludeContentInPackage)' == 'true' and '%(Content.Pack)' != 'false')">
58+
<Output TaskParameter="AssignedFiles" ItemName="_ContentToInfer" />
59+
</AssignTargetPath>
60+
61+
<AssignTargetPath Files="@(None)" RootFolder="$(MSBuildProjectDirectory)"
62+
Condition="'%(None.Pack)' == 'true' or
63+
'%(None.Kind)' != '' or
64+
('$(IncludeNoneInPackage)' == 'true' and '%(None.Pack)' != 'false')">
65+
<Output TaskParameter="AssignedFiles" ItemName="_NoneToInfer" />
66+
</AssignTargetPath>
67+
5368
<ItemGroup>
5469
<_InferredPackageFile Include="@(BuiltProjectOutputGroupOutput -> '%(FinalOutputPath)');@(BuiltProjectOutputGroupKeyOutput -> '%(FinalOutputPath)')"
5570
Condition="'$(IncludeOutputsInPackage)' == 'true' and '$(IsPackagingProject)' != 'true'">
@@ -85,51 +100,28 @@ Copyright (c) .NET Foundation. All rights reserved.
85100
<FrameworkSpecific>$(PrimaryOutputFrameworkSpecific)</FrameworkSpecific>
86101
</_InferredPackageFile>
87102

103+
88104
<!-- NOTE: Content is opt-out (must have Pack=false to exclude if IncludeContentInPackage=true) -->
89105
<!-- Stuff that is copied to output should be included from that output location -->
90-
<_InferredPackageFile Include="@(ContentWithTargetPath->'$(OutputPath)%(TargetPath)')"
91-
Condition="
92-
'%(ContentWithTargetPath.CopyToOutputDirectory)' != '' and
93-
(
94-
'%(ContentWithTargetPath.Pack)' == 'true' or
95-
'%(ContentWithTargetPath.Kind)' != '' or
96-
('$(IncludeContentInPackage)' == 'true' and '%(ContentWithTargetPath.Pack)' != 'false')
97-
)">
98-
<Kind Condition="'%(ContentWithTargetPath.Kind)' == '' and '%(ContentWithTargetPath.CopyToOutputDirectory)' != ''">$(PrimaryOutputKind)</Kind>
106+
<_InferredPackageFile Include="@(_ContentToInfer->'$(OutputPath)%(TargetPath)')"
107+
Condition="'%(_ContentToInfer.CopyToOutputDirectory)' != ''">
108+
<Kind Condition="'%(_ContentToInfer.Kind)' == ''">$(PrimaryOutputKind)</Kind>
99109
</_InferredPackageFile>
100-
<!-- Otherwise, include from source location -->
101-
<_InferredPackageFile Include="@(ContentWithTargetPath->'%(FullPath)')"
102-
Condition="
103-
'%(ContentWithTargetPath.CopyToOutputDirectory)' == '' and
104-
(
105-
'%(ContentWithTargetPath.Pack)' == 'true' or
106-
'%(ContentWithTargetPath.Kind)' != '' or
107-
('$(IncludeContentInPackage)' == 'true' and '%(ContentWithTargetPath.Pack)' != 'false')
108-
)">
109-
<Kind Condition="'%(ContentWithTargetPath.Kind)' == ''">Content</Kind>
110+
<!-- Otherwise, include from source location and default to content -->
111+
<_InferredPackageFile Include="@(_ContentToInfer->'%(FullPath)')"
112+
Condition="'%(_ContentToInfer.CopyToOutputDirectory)' == ''">
113+
<Kind Condition="'%(_ContentToInfer.Kind)' == ''">Content</Kind>
110114
</_InferredPackageFile>
111115

112116
<!-- NOTE: None is also opt-out (must have Pack=false to exclude if IncludeNoneInPackage=true, but this property defaults to false) -->
113117
<!-- Likewise, include from target path if it's copied, from source path otherwise -->
114-
<_InferredPackageFile Include="@(_NoneWithTargetPath->'$(OutputPath)%(TargetPath)')"
115-
Condition="
116-
'%(_NoneWithTargetPath.CopyToOutputDirectory)' != '' and
117-
(
118-
'%(_NoneWithTargetPath.Pack)' == 'true' or
119-
'%(_NoneWithTargetPath.Kind)' != '' or
120-
('$(IncludeNoneInPackage)' == 'true' and '%(_NoneWithTargetPath.Pack)' != 'false')
121-
)">
122-
<Kind Condition="'%(_NoneWithTargetPath.Kind)' == '' and '%(_NoneWithTargetPath.CopyToOutputDirectory)' != ''">$(PrimaryOutputKind)</Kind>
118+
<_InferredPackageFile Include="@(_NoneToInfer->'$(OutputPath)%(TargetPath)')"
119+
Condition="'%(_NoneToInfer.CopyToOutputDirectory)' != ''">
120+
<Kind Condition="'%(_NoneToInfer.Kind)' == ''">$(PrimaryOutputKind)</Kind>
123121
</_InferredPackageFile>
124-
<_InferredPackageFile Include="@(_NoneWithTargetPath->'%(FullPath)')"
125-
Condition="
126-
'%(_NoneWithTargetPath.CopyToOutputDirectory)' == '' and
127-
(
128-
'%(_NoneWithTargetPath.Pack)' == 'true' or
129-
'%(_NoneWithTargetPath.Kind)' != '' or
130-
('$(IncludeNoneInPackage)' == 'true' and '%(_NoneWithTargetPath.Pack)' != 'false')
131-
)">
132-
<Kind Condition="'%(_NoneWithTargetPath.Kind)' == ''">None</Kind>
122+
<_InferredPackageFile Include="@(_NoneToInfer->'%(FullPath)')"
123+
Condition="'%(_NoneToInfer.CopyToOutputDirectory)' == ''">
124+
<Kind Condition="'%(_NoneToInfer.Kind)' == ''">None</Kind>
133125
</_InferredPackageFile>
134126

135127

src/Build/NuGet.Build.Packaging.Tasks/NuGet.Build.Packaging.Legacy.targets

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ Copyright (c) .NET Foundation. All rights reserved.
1616
BeforeTargets="InferPackageContents"
1717
DependsOnTargets="$(InferPackageContentsDependsOn)">
1818
<ItemGroup>
19-
<!-- From InferPackageContents -->
20-
<ContentWithTargetPath Condition="'%(ContentWithTargetPath.IncludeInPackage)' != ''">
21-
<Pack>%(ContentWithTargetPath.IncludeInPackage)</Pack>
22-
</ContentWithTargetPath>
23-
<_NoneWithTargetPath Condition="'%(_NoneWithTargetPath.IncludeInPackage)' != ''">
24-
<Pack>%(_NoneWithTargetPath.IncludeInPackage)</Pack>
25-
</_NoneWithTargetPath>
19+
<!-- For InferPackageContents -->
20+
<Content Condition="'%(Content.IncludeInPackage)' != ''">
21+
<Pack>%(Content.IncludeInPackage)</Pack>
22+
</Content>
23+
<None Condition="'%(None.IncludeInPackage)' != ''">
24+
<Pack>%(None.IncludeInPackage)</Pack>
25+
</None>
2626
</ItemGroup>
2727
</Target>
2828

0 commit comments

Comments
 (0)