diff --git a/src/NuGetizer.Tasks/NuGetizer.Inference.targets b/src/NuGetizer.Tasks/NuGetizer.Inference.targets index a5469ef2..e6cfac15 100644 --- a/src/NuGetizer.Tasks/NuGetizer.Inference.targets +++ b/src/NuGetizer.Tasks/NuGetizer.Inference.targets @@ -98,7 +98,7 @@ Copyright (c) .NET Foundation. All rights reserved. content true AndroidResource - + content true @@ -117,12 +117,17 @@ Copyright (c) .NET Foundation. All rights reserved. - + + + + + + false false @@ -158,7 +163,7 @@ Copyright (c) .NET Foundation. All rights reserved. @(_BuildOutputFrameworkSpecific) - + @@ -167,7 +172,7 @@ Copyright (c) .NET Foundation. All rights reserved. Pack="false" /> - + @@ -191,10 +196,10 @@ Copyright (c) .NET Foundation. All rights reserved. '%(_InferenceCandidateWithTargetPath.CopyToOutputDirectory)' != 'Never'">$(PackFolder) %(_InferenceCandidateWithTargetPath.DefaultPackFolder) + '%(_InferenceCandidateWithTargetPath.CopyToOutputDirectory)' == 'Never'">%(_InferenceCandidateWithTargetPath.DefaultPackFolder) - - + + <_InferredPackageFile Include="@(_InferenceCandidateWithTargetPath -> '$(_OutputFullPath)\%(TargetPath)')" Condition="'%(_InferenceCandidateWithTargetPath.CopyToOutputDirectory)' != '' and '%(_InferenceCandidateWithTargetPath.CopyToOutputDirectory)' != 'Never'" /> @@ -205,12 +210,12 @@ Copyright (c) .NET Foundation. All rights reserved. - - <_SatelliteDllsProjectOutputGroupOutput Include="@(SatelliteDllsProjectOutputGroupOutput)" + <_SatelliteDllsProjectOutputGroupOutput Include="@(SatelliteDllsProjectOutputGroupOutput)" FinalOutputPath="%(FullPath)" /> - + <_InferredProjectOutput Include="@(BuiltProjectOutputGroupOutput -> '%(FinalOutputPath)'); @(BuiltProjectOutputGroupKeyOutput -> '%(FinalOutputPath)'); @(DocumentationProjectOutputGroupOutput -> '%(FinalOutputPath)'); @@ -263,9 +268,9 @@ Copyright (c) .NET Foundation. All rights reserved. - @@ -277,7 +282,7 @@ Copyright (c) .NET Foundation. All rights reserved. - <_CentrallyManagedDependency Include="@(PackageDependencies)" + <_CentrallyManagedDependency Include="@(PackageDependencies)" Condition="$([MSBuild]::ValueOrDefault('%(Identity)', '').StartsWith('$(_CandidatePackageId)/')) and $([MSBuild]::ValueOrDefault('%(ParentPackage)', '')) == ''" /> @@ -286,13 +291,13 @@ Copyright (c) .NET Foundation. All rights reserved. <_CentrallyManagedDependency>%(_CentrallyManagedDependency.Identity) <_CentrallyManagedVersion>$(_CentrallyManagedDependency.Replace('$(_CandidatePackageId)/', '')) - + - + - + @@ -305,13 +310,13 @@ Copyright (c) .NET Foundation. All rights reserved. <_PrivateAssetsPackageReference Include="@(PackageReference -> WithMetadataValue('PrivateAssets', 'all'))" Condition="'%(PackageReference.IsImplicitlyDefined)' != 'true' and '%(PackageReference.Pack)' != 'false'"/> - - + - + <_NuGetPackageId Include="@(_PrimaryOutputRelatedFile -> '%(NuGetPackageId)')" Condition="'%(NuGetPackageId)' != 'NETStandard.Library'" /> @@ -327,12 +332,12 @@ Copyright (c) .NET Foundation. All rights reserved. <_NuGetPackageId>@(_NuGetPackageId -> Distinct()) - <_PrimaryPackageReference Include="@(PackageReference);@(ImplicitPackageReference)" Condition="'$(_NuGetPackageId)' != '' and '%(Identity)' == '$(_NuGetPackageId)'" /> + <_PrimaryPackageReference Include="@(ImplicitPackageReference);@(PackageReference)" Condition="'$(_NuGetPackageId)' != '' and '%(Identity)' == '$(_NuGetPackageId)'" /> - + - <_PrivateAssets>@(_PrimaryPackageReference -> '%(PrivateAssets)') - <_ShouldPack>@(_PrimaryPackageReference -> '%(Pack)') + <_PrivateAssets>%(_PrimaryPackageReference.PrivateAssets) + <_ShouldPack>%(_PrimaryPackageReference.Pack) <_ShouldIncludeAssetsRegex>$(_NuGetPackageId)\\.+\\$(_PrivateAssets)\\.* @@ -347,7 +352,7 @@ Copyright (c) .NET Foundation. All rights reserved. - <_InferredPackageFile Include="@(_PrimaryOutputRelatedFile)" + <_InferredPackageFile Include="@(_PrimaryOutputRelatedFile)" Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('%(_PrimaryOutputRelatedFile.FullPath)', '$(_ShouldIncludeAssetsRegex)', 'RegexOptions.IgnoreCase')) == 'true'"> $(PackFolder) $(BuildOutputFrameworkSpecific) @@ -376,7 +381,7 @@ Copyright (c) .NET Foundation. All rights reserved. '$(ManagePackageVersionsCentrally)' == 'true'"> $(InferPackageContentsDependsOn); _UpdatePackageReferenceVersions - + $(InferPackageContentsDependsOn); GetPackageTargetPath diff --git a/src/NuGetizer.Tests/given_packinference.cs b/src/NuGetizer.Tests/given_packinference.cs index d0e370fe..15fadba2 100644 --- a/src/NuGetizer.Tests/given_packinference.cs +++ b/src/NuGetizer.Tests/given_packinference.cs @@ -540,5 +540,29 @@ public void when_adding_new_inference_then_can_change_defaults() Extension = ".sql", })); } + + [Fact] + public void when_direct_and_indirect_packagereference_then_packs_once() + { + var result = Builder.BuildProject(@" + + + Library + net472 + + + + + +", + "GetPackageContents", output); + + result.AssertSuccess(output); + Assert.Contains(result.Items, item => item.Matches(new + { + Filename = "Microsoft.VisualStudio.Shell.Interop", + Extension = ".dll", + })); + } } }