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

Commit b82e84d

Browse files
committed
Use $(IsPackable) everywhere we read $(PackageId)
At the top of the targets file, we default `$(IsPackable)` to true if `$(PackageId)` is not empty. .NETStandard projects currently *always* assign a value to that property, matching the `$(AssemblyName)`, therefore breaking our logic. To improve compatibility, we can check for the `$(IsPackable)` property instead, so that while more alignment is achieved, at least an explicit `$(IsPackable)==false` can be set for those projects and keep our logic consistent in that case. That involves never assuming the `$(PackageId)` will be empty before assigning it as metadata on items, and always checking for `$(IsPackable)==true` instead.
1 parent 4e35cf9 commit b82e84d

1 file changed

Lines changed: 65 additions & 64 deletions

File tree

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

Lines changed: 65 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -215,53 +215,54 @@ Copyright (c) .NET Foundation. All rights reserved.
215215
</PropertyGroup>
216216
<Target Name="GetPackageContents" DependsOnTargets="$(GetPackageContentsDependsOn)" Returns="@(_PackageContent)">
217217
<Error Condition="'@(_NonNuGetizedProjectReference)' != ''"
218-
Code="NG0011"
219-
Text="Some project references cannot be properly packaged. Please install the NuGet.Build.Packaging package on the following projects: @(_NonNuGetizedProjectReference)." />
218+
Code="NG0011"
219+
Text="Some project references cannot be properly packaged. Please install the NuGet.Build.Packaging package on the following projects: @(_NonNuGetizedProjectReference)." />
220220

221221
<!-- PackageId metadata on all PackageFile items means we can tell appart which ones came from which dependencies
222222
NOTE: if PackageId is empty, we won't generate a manifest and it means the files need to be packed with the
223223
current project. -->
224+
224225
<ItemGroup>
225226
<PackageFile Include="@(BuiltProjectOutputGroupOutput -> '%(FinalOutputPath)')"
226-
Condition="'$(IncludeOutputsInPackage)' == 'true' and '$(IsPackagingProject)' != 'true'">
227+
Condition="'$(IncludeOutputsInPackage)' == 'true' and '$(IsPackagingProject)' != 'true'">
227228
<!-- Packaging projects don't contribute primary output -->
228229
<Kind>$(PrimaryOutputPackageFileKind)</Kind>
229230
</PackageFile>
230231

231232
<!-- Remove when https://github.com/Microsoft/msbuild/pull/1076 ships -->
232233
<_DocumentationProjectOutputGroupOutput Include="@(DocumentationProjectOutputGroupOutput)"
233-
Condition="'$(IncludeOutputsInPackage)' == 'true'">
234+
Condition="'$(IncludeOutputsInPackage)' == 'true'">
234235
<FinalOutputPath Condition="$([System.IO.Path]::IsPathRooted('%(FinalOutputPath)')) == 'false'">$(MSBuildProjectDirectory)\%(FinalOutputPath)</FinalOutputPath>
235236
</_DocumentationProjectOutputGroupOutput>
236237
<PackageFile Include="@(_DocumentationProjectOutputGroupOutput -> '%(FinalOutputPath)')"
237-
Condition="'$(IncludeOutputsInPackage)' == 'true' and '$(IsPackagingProject)' != 'true'">
238+
Condition="'$(IncludeOutputsInPackage)' == 'true' and '$(IsPackagingProject)' != 'true'">
238239
<!-- Packaging projects don't contribute primary docs -->
239240
<Kind>$(PrimaryOutputPackageFileKind)</Kind>
240241
</PackageFile>
241242

242243
<PackageFile Include="@(DebugSymbolsProjectOutputGroupOutput -> '%(FinalOutputPath)')"
243-
Condition="'$(IncludeOutputsInPackage)' == 'true' and '$(IncludeSymbolsInPackage)' == 'true' and '$(IsPackagingProject)' != 'true'">
244+
Condition="'$(IncludeOutputsInPackage)' == 'true' and '$(IncludeSymbolsInPackage)' == 'true' and '$(IsPackagingProject)' != 'true'">
244245
<!-- Packaging projects don't contribute primary symbols -->
245246
<Kind>$(PrimaryOutputPackageFileKind)</Kind>
246247
</PackageFile>
247248

248249
<!-- Change to %(FinalOutputPath) when https://github.com/Microsoft/msbuild/pull/1115 ships -->
249250
<PackageFile Include="@(SatelliteDllsProjectOutputGroupOutput -> '%(FullPath)')"
250-
Condition="'$(IncludeOutputsInPackage)' == 'true' and '$(IsPackagingProject)' != 'true'">
251+
Condition="'$(IncludeOutputsInPackage)' == 'true' and '$(IsPackagingProject)' != 'true'">
251252
<!-- Packaging projects don't contribute satellite dlls -->
252253
<Kind>$(PrimaryOutputPackageFileKind)</Kind>
253254
</PackageFile>
254255

255256
<!-- NOTE: Content is opt-out (must have IncludeInPackage=false to exclude) -->
256257
<!-- @ContentFilesProjectOutputGroupOutput = @(ContentWithTargetPath->'%(FullPath)') -->
257258
<PackageFile Include="@(ContentFilesProjectOutputGroupOutput)"
258-
Condition="'$(IncludeContentInPackage)' == 'true' and '%(ContentFilesProjectOutputGroupOutput.IncludeInPackage)' != 'false'">
259+
Condition="'$(IncludeContentInPackage)' == 'true' and '%(ContentFilesProjectOutputGroupOutput.IncludeInPackage)' != 'false'">
259260
<Kind>Content</Kind>
260261
</PackageFile>
261262

262263
<!-- NOTE: None is opt-in (must have IncludeInPackage=true to include) -->
263264
<PackageFile Include="@(_NoneWithTargetPath)"
264-
Condition="'%(_NoneWithTargetPath.IncludeInPackage)' == 'true'">
265+
Condition="'%(_NoneWithTargetPath.IncludeInPackage)' == 'true'">
265266
<Kind>None</Kind>
266267
</PackageFile>
267268

@@ -273,21 +274,21 @@ Copyright (c) .NET Foundation. All rights reserved.
273274
it also includes mscorlib which we don't need
274275
TBD: maybe include ResolvedFrom=ImplicitlyExpandDesignTimeFacades too? -->
275276
<PackageFile Include="@(ReferencePath->'%(OriginalItemSpec)')"
276-
Condition="'$(IncludeFrameworkReferencesInPackage)' == 'true' and '%(ReferencePath.ResolvedFrom)' == '{TargetFrameworkDirectory}'">
277+
Condition="'$(IncludeFrameworkReferencesInPackage)' == 'true' and '%(ReferencePath.ResolvedFrom)' == '{TargetFrameworkDirectory}'">
277278
<Kind>FrameworkReference</Kind>
278279
</PackageFile>
279280
</ItemGroup>
280281

281282
<!-- If packaging the project, provide the metadata as a non-file item -->
282-
<ItemGroup Condition="'$(PackageId)' != ''">
283+
<ItemGroup Condition="'$(IsPackable)' == 'true'">
283284
<PackageFile Include="@(PackageTargetPath->'%(Id)')">
284285
<Kind>Metadata</Kind>
285286
</PackageFile>
286287
</ItemGroup>
287288

288289
<ItemGroup>
289290
<PackageFile>
290-
<PackageId>$(PackageId)</PackageId>
291+
<PackageId Condition="'$(IsPackable)' == 'true'">$(PackageId)</PackageId>
291292
<Platform>$(Platform)</Platform>
292293
<TargetFrameworkMoniker Condition="'$(IsPackagingProject)' != 'true'">$(TargetFrameworkMoniker)</TargetFrameworkMoniker>
293294
</PackageFile>
@@ -298,40 +299,40 @@ Copyright (c) .NET Foundation. All rights reserved.
298299
</AssignPackagePath>
299300

300301
<MSBuild Projects="@(_NuGetizedProjectReference)"
301-
Targets="GetPackageContents"
302-
BuildInParallel="$(BuildInParallel)"
303-
Properties="%(_NuGetizedProjectReference.SetConfiguration); %(_NuGetizedProjectReference.SetPlatform); BuildingPackage=$(BuildingPackage)"
304-
Condition="'@(ProjectReferenceWithConfiguration)' != '' and '@(_NuGetizedProjectReference)' != ''"
305-
RemoveProperties="%(_NuGetizedProjectReference.GlobalPropertiesToRemove)">
302+
Targets="GetPackageContents"
303+
BuildInParallel="$(BuildInParallel)"
304+
Properties="%(_NuGetizedProjectReference.SetConfiguration); %(_NuGetizedProjectReference.SetPlatform); BuildingPackage=$(BuildingPackage)"
305+
Condition="'@(ProjectReferenceWithConfiguration)' != '' and '@(_NuGetizedProjectReference)' != ''"
306+
RemoveProperties="%(_NuGetizedProjectReference.GlobalPropertiesToRemove)">
306307
<Output TaskParameter="TargetOutputs" ItemName="_ReferencedPackageContent" />
307308
</MSBuild>
308309

309310
<ItemGroup>
310311
<_ReferencedPackageDependency Include="@(_ReferencedPackageContent)"
311-
Condition="'%(_ReferencedPackageContent.PackageId)' != '$(PackageId)' and '%(_ReferencedPackageContent.Kind)' == 'Metadata'">
312+
Condition="'%(_ReferencedPackageContent.PackageId)' != '$(PackageId)' and '%(_ReferencedPackageContent.Kind)' == 'Metadata'">
312313
<!-- For consistency, annotate like the rest -->
313-
<PackageId>$(PackageId)</PackageId>
314+
<PackageId Condition="'$(IsPackable)' == 'true'">$(PackageId)</PackageId>
314315
<TargetFrameworkMoniker Condition="'$(IsPackagingProject)' != 'true'">$(TargetFrameworkMoniker)</TargetFrameworkMoniker>
315316
<Kind>Dependency</Kind>
316317
</_ReferencedPackageDependency>
317318
<!-- Remove the referenced package actual contents if it provides a manifest, since it will be a dependency in that case. -->
318319
<_PackageContentFromDependency Include="@(_ReferencedPackageContent)"
319-
Condition="'%(_ReferencedPackageContent.PackageId)' != '' and
320+
Condition="'%(_ReferencedPackageContent.PackageId)' != '' and
320321
'%(_ReferencedPackageContent.PackageId)' != '$(PackageId)'" />
321322
<_ReferencedPackageContent Remove="@(_PackageContentFromDependency)" />
322323
</ItemGroup>
323324

324325
<!-- Always annotate package contents with the original target framework and moniker -->
325326
<CreateItem Include="@(_ReferencedPackageContent)" PreserveExistingMetadata="true"
326-
Condition="'@(_ReferencedPackageContent)' != ''"
327-
AdditionalMetadata="OriginalTargetFramework=%(TargetFramework);OriginalTargetFrameworkMoniker=%(TargetFrameworkMoniker)">
327+
Condition="'@(_ReferencedPackageContent)' != ''"
328+
AdditionalMetadata="OriginalTargetFramework=%(TargetFramework);OriginalTargetFrameworkMoniker=%(TargetFrameworkMoniker)">
328329
<Output TaskParameter="Include" ItemName="_ReferencedPackageContentWithOriginalValues"/>
329330
</CreateItem>
330331

331332
<ItemGroup Condition="'$(IsPackagingProject)' != 'true'">
332333
<!-- Retarget content for the currently building package, if necessary -->
333334
<_ReferencedPackageContentWithOriginalValues Condition="'%(_ReferencedPackageContentWithOriginalValues.PackageId)' == ''">
334-
<PackageId>$(PackageId)</PackageId>
335+
<PackageId Condition="'$(IsPackable)' == 'true'">$(PackageId)</PackageId>
335336
<!-- Clear the target framework since it trumps the TFM in AsignPackagePath now -->
336337
<!-- Only do this for Library assets that come from project references that don't build nugets (PackageId=='' above) -->
337338
<TargetFramework Condition="'%(_ReferencedPackageContentWithOriginalValues.Kind)' == 'Lib' or
@@ -350,7 +351,7 @@ Copyright (c) .NET Foundation. All rights reserved.
350351
<ItemGroup Condition="'$(IsPackagingProject)' == 'true'">
351352
<!-- Retarget content for the currently building package, if necessary -->
352353
<_ReferencedPackageContentWithOriginalValues Condition="'%(_ReferencedPackageContentWithOriginalValues.PackageId)' == ''">
353-
<PackageId>$(PackageId)</PackageId>
354+
<PackageId Condition="'$(IsPackable)' == 'true'">$(PackageId)</PackageId>
354355
<!-- Clear the target framework since it trumps the TFM in AsignPackagePath now -->
355356
<!-- Only do this for Library assets that come from project references that don't build nugets (PackageId=='' above) -->
356357
<TargetFramework Condition="'%(_ReferencedPackageContentWithOriginalValues.Kind)' == 'Lib' or
@@ -364,24 +365,24 @@ Copyright (c) .NET Foundation. All rights reserved.
364365
depend on the referencing project's TFM.
365366
-->
366367
<AssignPackagePath Files="@(_ReferencedPackageContentWithOriginalValues);@(_ReferencedPackageDependency)"
367-
Kinds="@(PackageItemKind)"
368-
IsPackaging="$(BuildingPackage)"
369-
Condition="'@(_ReferencedPackageContentWithOriginalValues)' != '' Or '@(_ReferencedPackageDependency)' != ''">
368+
Kinds="@(PackageItemKind)"
369+
IsPackaging="$(BuildingPackage)"
370+
Condition="'@(_ReferencedPackageContentWithOriginalValues)' != '' Or '@(_ReferencedPackageDependency)' != ''">
370371
<Output TaskParameter="AssignedFiles" ItemName="_PackageContent" />
371372
</AssignPackagePath>
372373
</Target>
373374

374375
<!-- This target separates project references that have the packaging targets from those that don't -->
375376
<Target Name="_SplitProjectReferencesByIsNuGetized"
376-
Condition="'@(ProjectReferenceWithConfiguration)' != '' and '@(_MSBuildProjectReferenceExistent)' != ''"
377-
Inputs="@(_MSBuildProjectReferenceExistent)"
378-
Outputs="%(_MSBuildProjectReferenceExistent.Identity)-BATCH">
377+
Condition="'@(ProjectReferenceWithConfiguration)' != '' and '@(_MSBuildProjectReferenceExistent)' != ''"
378+
Inputs="@(_MSBuildProjectReferenceExistent)"
379+
Outputs="%(_MSBuildProjectReferenceExistent.Identity)-BATCH">
379380

380381
<MSBuild Projects="@(_MSBuildProjectReferenceExistent)"
381-
Targets="GetTargetPathWithTargetPlatformMoniker"
382-
BuildInParallel="$(BuildInParallel)"
383-
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform)"
384-
RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
382+
Targets="GetTargetPathWithTargetPlatformMoniker"
383+
BuildInParallel="$(BuildInParallel)"
384+
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform)"
385+
RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
385386
<Output TaskParameter="TargetOutputs" ItemName="_ReferencedProjectTargetPath" />
386387
</MSBuild>
387388

@@ -391,11 +392,11 @@ Copyright (c) .NET Foundation. All rights reserved.
391392

392393
<ItemGroup>
393394
<!-- We will fail for this first group: project references that aren't excluded from packaging, yet haven't been nugetized -->
394-
<_NonNuGetizedProjectReference Include="@(_MSBuildProjectReferenceExistent)"
395-
Condition="'%(_MSBuildProjectReferenceExistent.IncludeInPackage)' != 'false' and '$(_IsNuGetized)' != 'true'" />
395+
<_NonNuGetizedProjectReference Include="@(_MSBuildProjectReferenceExistent)"
396+
Condition="'%(_MSBuildProjectReferenceExistent.IncludeInPackage)' != 'false' and '$(_IsNuGetized)' != 'true'" />
396397
<!-- We will only process for packaging the project references that haven't been excluded from packaging and are nugetized -->
397-
<_NuGetizedProjectReference Include="@(_MSBuildProjectReferenceExistent)"
398-
Condition="'%(_MSBuildProjectReferenceExistent.IncludeInPackage)' != 'false' and '$(_IsNuGetized)' == 'true'" />
398+
<_NuGetizedProjectReference Include="@(_MSBuildProjectReferenceExistent)"
399+
Condition="'%(_MSBuildProjectReferenceExistent.IncludeInPackage)' != 'false' and '$(_IsNuGetized)' == 'true'" />
399400
</ItemGroup>
400401

401402
</Target>
@@ -491,15 +492,15 @@ Copyright (c) .NET Foundation. All rights reserved.
491492
</ItemGroup>
492493

493494
<MSBuild
494-
Projects="@(_ReferenceAssemblyProjects)"
495-
Targets="GetTargetPathWithTargetPlatformMoniker">
495+
Projects="@(_ReferenceAssemblyProjects)"
496+
Targets="GetTargetPathWithTargetPlatformMoniker">
496497
<Output TaskParameter="TargetOutputs" ItemName="IntersectionAssembly" />
497498
</MSBuild>
498499

499500
<GetApiIntersectTargetPaths
500-
Frameworks="%(ReferenceAssemblyFramework.Identity)"
501-
RootOutputDirectory="$(IntermediateOutputPath)"
502-
Assemblies="@(IntersectionAssembly)">
501+
Frameworks="%(ReferenceAssemblyFramework.Identity)"
502+
RootOutputDirectory="$(IntermediateOutputPath)"
503+
Assemblies="@(IntersectionAssembly)">
503504
<Output TaskParameter="TargetPaths" ItemName="_ReferenceAssemblyTargetPath" />
504505
</GetApiIntersectTargetPaths>
505506

@@ -512,10 +513,10 @@ Copyright (c) .NET Foundation. All rights reserved.
512513
</Target>
513514

514515
<Target Name="_GenerateReferenceAssemblies"
515-
DependsOnTargets="_GetReferenceAssemblyTargetPaths"
516-
Condition=" '@(ReferenceAssemblyFramework)' != '' "
517-
Inputs="@(IntersectionAssembly)"
518-
Outputs="@(_ReferenceAssemblyTargetPath)">
516+
DependsOnTargets="_GetReferenceAssemblyTargetPaths"
517+
Condition=" '@(ReferenceAssemblyFramework)' != '' "
518+
Inputs="@(IntersectionAssembly)"
519+
Outputs="@(_ReferenceAssemblyTargetPath)">
519520

520521
<PropertyGroup>
521522
<EnableDefaultIntersectionAssemblyReferencePath Condition="'$(EnableDefaultIntersectionAssemblyReferencePath)' == ''">true</EnableDefaultIntersectionAssemblyReferencePath>
@@ -525,31 +526,31 @@ Copyright (c) .NET Foundation. All rights reserved.
525526
<_IntersectionReferencePath Include="@(IntersectionAssembly->'%(RootDir)%(Directory)')" Condition="'$(EnableDefaultIntersectionAssemblyReferencePath)' == 'true'" />
526527
<_IntersectionReferencePath Include="$(IntersectionAssemblyReferencePath)" />
527528
</ItemGroup>
528-
529+
529530
<ApiIntersect
530-
Framework="%(ReferenceAssemblyFramework.Identity)"
531-
RootOutputDirectory="$(IntermediateOutputPath)"
532-
IntersectionAssembly="@(IntersectionAssembly)"
533-
ReferencePath="@(_IntersectionReferencePath)"
534-
ExcludeType="$(IntersectionExcludeType)"
535-
RemoveAbstractTypeMembers="$(IntersectionRemoveAbstractTypeMembers)"
536-
ExcludeAssembly="@(IntersectionExcludeAssembly)"
537-
KeepInternalConstructors="$(IntersectionKeepInternalConstructors)"
538-
KeepMarshalling="$(IntersectionKeepMarshalling)"
539-
ToolPath="$(ApiIntersectToolPath)"
540-
ToolExe="$(ApiIntersectToolExe)">
531+
Framework="%(ReferenceAssemblyFramework.Identity)"
532+
RootOutputDirectory="$(IntermediateOutputPath)"
533+
IntersectionAssembly="@(IntersectionAssembly)"
534+
ReferencePath="@(_IntersectionReferencePath)"
535+
ExcludeType="$(IntersectionExcludeType)"
536+
RemoveAbstractTypeMembers="$(IntersectionRemoveAbstractTypeMembers)"
537+
ExcludeAssembly="@(IntersectionExcludeAssembly)"
538+
KeepInternalConstructors="$(IntersectionKeepInternalConstructors)"
539+
KeepMarshalling="$(IntersectionKeepMarshalling)"
540+
ToolPath="$(ApiIntersectToolPath)"
541+
ToolExe="$(ApiIntersectToolExe)">
541542
<Output TaskParameter="OutputDirectory" ItemName="_ReferenceAssemblyBuildInfo" />
542543
</ApiIntersect>
543544

544545
<GenerateAssemblyInfo
545-
Assemblies="@(IntersectionAssembly)"
546-
OutputDirectories="@(_ReferenceAssemblyBuildInfo->'%(Identity)Contract')">
546+
Assemblies="@(IntersectionAssembly)"
547+
OutputDirectories="@(_ReferenceAssemblyBuildInfo->'%(Identity)Contract')">
547548
<Output TaskParameter="AssemblyName" PropertyName="_ReferenceAssemblyName" />
548549
</GenerateAssemblyInfo>
549550

550551
<MSBuild
551-
Projects="$(MSBuildThisFileDirectory)GenerateReferenceAssembly.csproj"
552-
Properties="
552+
Projects="$(MSBuildThisFileDirectory)GenerateReferenceAssembly.csproj"
553+
Properties="
553554
AssemblyName=$(_ReferenceAssemblyName);
554555
SrcDir=%(_ReferenceAssemblyBuildInfo.FullPath);
555556
OutputPath=%(_ReferenceAssemblyBuildInfo.FullPath)bin\;
@@ -571,4 +572,4 @@ Copyright (c) .NET Foundation. All rights reserved.
571572
</Target>
572573

573574
<Import Project="NuGet.Build.Packaging.Authoring.targets" Condition="'$(IsPackagingProject)' == 'true'" />
574-
</Project>
575+
</Project>

0 commit comments

Comments
 (0)