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

Commit 4fbc5fe

Browse files
kzuadalon
authored andcommitted
Improve compatibility with SDK Pack by using %(Pack) metadata
NuGetizer relies on a %(IncludeInPackage) metadata item on ProjectReference, Content and None items in order to determine if they should be processed while packing. This represents an unnecessary migration burden on authors. We should unify on %(Pack) since it's shorter and explicit enough since it's item metadata and not a global property. We should do this renaming in a backwards compatible way with previous NuGetizer values, so that existing nugetized projects continue to work unchanged. Fixes NuGet/Home#5319
1 parent 4e76df1 commit 4fbc5fe

7 files changed

Lines changed: 72 additions & 26 deletions

src/Build/NuGet.Build.Packaging.Tasks/NuGet.Build.Packaging.Compatibility.targets renamed to src/Build/NuGet.Build.Packaging.Tasks/NuGet.Build.Packaging.Compatibility.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
22
***********************************************************************************************
3-
Microsoft.NuGet.Build.Packaging.Compatibility.targets
3+
Microsoft.NuGet.Build.Packaging.Compatibility.props
44
55
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
66
created a backup copy. Incorrect changes to this file will make it

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,23 +87,23 @@ Copyright (c) .NET Foundation. All rights reserved.
8787
<FrameworkSpecific>$(PrimaryOutputFrameworkSpecific)</FrameworkSpecific>
8888
</_InferredPackageFile>
8989

90-
<!-- NOTE: Content is opt-out (must have IncludeInPackage=false to exclude if IncludeContentInPackage=true) -->
90+
<!-- NOTE: Content is opt-out (must have Pack=false to exclude if IncludeContentInPackage=true) -->
9191
<!-- @ContentFilesProjectOutputGroupOutput = @(ContentWithTargetPath -> '%(FullPath)') -->
9292
<_InferredPackageFile Include="@(ContentWithTargetPath->'%(FullPath)')"
9393
Condition="
94-
'%(ContentWithTargetPath.IncludeInPackage)' == 'true' or
94+
'%(ContentWithTargetPath.Pack)' == 'true' or
9595
'%(ContentWithTargetPath.Kind)' != '' or
96-
('$(IncludeContentInPackage)' == 'true' and '%(ContentWithTargetPath.IncludeInPackage)' != 'false')">
96+
('$(IncludeContentInPackage)' == 'true' and '%(ContentWithTargetPath.Pack)' != 'false')">
9797
<Kind Condition="'%(ContentWithTargetPath.Kind)' == '' and '%(ContentWithTargetPath.CopyToOutputDirectory)' != ''">$(PrimaryOutputKind)</Kind>
9898
<Kind Condition="'%(ContentWithTargetPath.Kind)' == '' and '%(ContentWithTargetPath.CopyToOutputDirectory)' == ''">Content</Kind>
9999
</_InferredPackageFile>
100100

101-
<!-- NOTE: None is also opt-out (must have IncludeInPackage=false to exclude if IncludeNoneInPackage=true, but only for those with CopyToOutput) -->
101+
<!-- NOTE: None is also opt-out (must have Pack=false to exclude if IncludeNoneInPackage=true, but only for those with CopyToOutput) -->
102102
<_InferredPackageFile Include="@(_NoneWithTargetPath->'%(FullPath)')"
103103
Condition="
104-
'%(_NoneWithTargetPath.IncludeInPackage)' == 'true' or
104+
'%(_NoneWithTargetPath.Pack)' == 'true' or
105105
'%(_NoneWithTargetPath.Kind)' != '' or
106-
('$(IncludeNoneInPackage)' == 'true' and '%(_NoneWithTargetPath.CopyToOutputDirectory)' != '' and '%(_NoneWithTargetPath.IncludeInPackage)' != 'false')">
106+
('$(IncludeNoneInPackage)' == 'true' and '%(_NoneWithTargetPath.CopyToOutputDirectory)' != '' and '%(_NoneWithTargetPath.Pack)' != 'false')">
107107
<Kind Condition="'%(_NoneWithTargetPath.Kind)' == '' and '%(_NoneWithTargetPath.CopyToOutputDirectory)' != ''">$(PrimaryOutputKind)</Kind>
108108
</_InferredPackageFile>
109109

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!--
2+
***********************************************************************************************
3+
Microsoft.NuGet.Build.Packaging.Legacy.props
4+
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.
8+
9+
Copyright (c) .NET Foundation. All rights reserved.
10+
***********************************************************************************************
11+
-->
12+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
13+
<!-- This targets is used to adjust renamed properties, items and metadata -->
14+
15+
<PropertyGroup>
16+
<PrimaryOutputKind Condition="'$(PrimaryOutputKind)' == ''">$(PrimaryOutputPackageFileKind)</PrimaryOutputKind>
17+
18+
<!-- Previously, $(IncludeOutputsInPackage) == false disabled inclusion of project references -->
19+
<IncludeProjectReferencesInPackage Condition="'$(IncludeProjectReferencesInPackage)' == ''">$(IncludeOutputsInPackage)</IncludeProjectReferencesInPackage>
20+
</PropertyGroup>
21+
22+
</Project>

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,28 @@ Copyright (c) .NET Foundation. All rights reserved.
1212
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
1313
<!-- This targets is used to adjust renamed properties, items and metadata -->
1414

15-
<PropertyGroup>
16-
<PrimaryOutputKind Condition="'$(PrimaryOutputKind)' == ''">$(PrimaryOutputPackageFileKind)</PrimaryOutputKind>
15+
<Target Name="_RenameIncludeInPackageToPack"
16+
BeforeTargets="InferPackageContents"
17+
DependsOnTargets="$(InferPackageContentsDependsOn)">
18+
<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>
26+
</ItemGroup>
27+
</Target>
1728

18-
<!-- Previously, $(IncludeOutputsInPackage) == false disabled inclusion of project references -->
19-
<IncludeProjectReferencesInPackage Condition="'$(IncludeProjectReferencesInPackage)' == ''">$(IncludeOutputsInPackage)</IncludeProjectReferencesInPackage>
20-
</PropertyGroup>
29+
<Target Name="_RenameIncludeInPackageToPackReferences"
30+
BeforeTargets="AssignProjectConfiguration">
31+
<ItemGroup>
32+
<!-- From _GetReferencedPackageContents and _GetReferenceAssemblyTargetPaths -->
33+
<ProjectReference Condition="'%(ProjectReference.IncludeInPackage)' != ''">
34+
<Pack>%(ProjectReference.IncludeInPackage)</Pack>
35+
</ProjectReference>
36+
</ItemGroup>
37+
</Target>
2138

2239
</Project>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Copyright (c) .NET Foundation. All rights reserved.
2828
DependsOnTargets="AssignProjectConfiguration;_SplitProjectReferencesByFileExistence"
2929
Condition="'@(ReferenceAssemblyFramework)' != ''">
3030
<ItemGroup>
31-
<_ReferenceAssemblyProjects Include="@(_MSBuildProjectReferenceExistent)" Condition="'%(_MSBuildProjectReferenceExistent.IncludeInPackage)' != 'false'" />
31+
<_ReferenceAssemblyProjects Include="@(_MSBuildProjectReferenceExistent)" Condition="'%(_MSBuildProjectReferenceExistent.Pack)' != 'false'" />
3232
</ItemGroup>
3333

3434
<MSBuild

src/Build/NuGet.Build.Packaging.Tasks/NuGet.Build.Packaging.Tasks.csproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
<Content Include="NuGet.Build.Packaging.Authoring.targets">
4949
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
5050
</Content>
51-
<Content Include="NuGet.Build.Packaging.Compatibility.targets">
51+
<None Include="NuGet.Build.Packaging.Compatibility.props">
5252
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
53-
</Content>
53+
</None>
5454
<Content Include="NuGet.Build.Packaging.ReferenceAssembly.targets">
5555
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
5656
</Content>
@@ -66,6 +66,9 @@
6666
<Content Include="GenerateReferenceAssembly.csproj">
6767
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
6868
</Content>
69+
<Content Include="NuGet.Build.Packaging.Legacy.props">
70+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
71+
</Content>
6972
<None Include="NuGet.Build.Packaging.Version.props">
7073
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
7174
</None>

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ Copyright (c) .NET Foundation. All rights reserved.
1515

1616
<Import Project="NuGet.Build.Packaging.props" Condition="'$(NuGetBuildPackagingPropsImported)' == ''" />
1717
<!-- Adds compatibility targets with Pack SDK -->
18-
<Import Project="NuGet.Build.Packaging.Compatibility.targets" />
19-
<Import Project="NuGet.Build.Packaging.Legacy.targets" />
18+
<Import Project="NuGet.Build.Packaging.Compatibility.props" />
19+
<Import Project="NuGet.Build.Packaging.Legacy.props" />
2020

2121
<PropertyGroup>
2222
<!-- Whether include referenced projects' contents the package -->
@@ -313,10 +313,10 @@ Copyright (c) .NET Foundation. All rights reserved.
313313
Outputs="%(_MSBuildProjectReferenceExistent.Identity)-BATCH">
314314

315315
<MSBuild Projects="@(_MSBuildProjectReferenceExistent)"
316-
Targets="GetTargetPathWithTargetPlatformMoniker"
317-
BuildInParallel="$(BuildInParallel)"
318-
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform)"
319-
RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
316+
Targets="GetTargetPathWithTargetPlatformMoniker"
317+
BuildInParallel="$(BuildInParallel)"
318+
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform)"
319+
RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
320320
<Output TaskParameter="TargetOutputs" ItemName="_ReferencedProjectTargetPath" />
321321
</MSBuild>
322322

@@ -326,11 +326,9 @@ Copyright (c) .NET Foundation. All rights reserved.
326326

327327
<ItemGroup>
328328
<!-- We will fail for this first group: project references that aren't excluded from packaging, yet haven't been nugetized -->
329-
<_NonNuGetizedProjectReference Include="@(_MSBuildProjectReferenceExistent)"
330-
Condition="'%(_MSBuildProjectReferenceExistent.IncludeInPackage)' != 'false' and '$(_IsNuGetized)' != 'true'" />
329+
<_NonNuGetizedProjectReference Include="@(_MSBuildProjectReferenceExistent)" Condition="'%(_MSBuildProjectReferenceExistent.Pack)' != 'false' and '$(_IsNuGetized)' != 'true'" />
331330
<!-- We will only process for packaging the project references that haven't been excluded from packaging and are nugetized -->
332-
<_NuGetizedProjectReference Include="@(_MSBuildProjectReferenceExistent)"
333-
Condition="'%(_MSBuildProjectReferenceExistent.IncludeInPackage)' != 'false' and '$(_IsNuGetized)' == 'true'" />
331+
<_NuGetizedProjectReference Include="@(_MSBuildProjectReferenceExistent)" Condition="'%(_MSBuildProjectReferenceExistent.Pack)' != 'false' and '$(_IsNuGetized)' == 'true'" />
334332
</ItemGroup>
335333

336334
</Target>
@@ -379,11 +377,17 @@ Copyright (c) .NET Foundation. All rights reserved.
379377
<_AllProjectCapabilities>@(ProjectCapability)</_AllProjectCapabilities>
380378
<!-- NOTE: this avoids taking dependencies on targets that are only available when the project supports the concept of project references -->
381379
<_SupportsProjectReferences>$(_AllProjectCapabilities.Contains('ProjectReferences'))</_SupportsProjectReferences>
382-
<_GetReferencedPackageContentsDependsOn Condition="'$(_SupportsProjectReferences)' == 'true'">AssignProjectConfiguration;_SplitProjectReferencesByFileExistence;_SplitProjectReferencesByIsNuGetized</_GetReferencedPackageContentsDependsOn>
380+
<_GetReferencedPackageContentsDependsOn Condition="'$(_SupportsProjectReferences)' == 'true'">
381+
$(_GetReferencedPackageContentsDependsOn);
382+
AssignProjectConfiguration;
383+
_SplitProjectReferencesByFileExistence;
384+
_SplitProjectReferencesByIsNuGetized
385+
</_GetReferencedPackageContentsDependsOn>
383386
</PropertyGroup>
384387
</Target>
385388

386389
<Import Project="NuGet.Build.Packaging.ReferenceAssembly.targets" />
387390
<Import Project="NuGet.Build.Packaging.Authoring.targets" Condition="'$(IsPackagingProject)' == 'true'" />
388391
<Import Project="NuGet.Build.Packaging.CrossTargeting.targets" Condition="'$(IsCrossTargetingBuild)' == 'true' And '$(FromPackagingProject)' == 'true'" />
392+
<Import Project="NuGet.Build.Packaging.Legacy.targets" />
389393
</Project>

0 commit comments

Comments
 (0)