From 99da0fd7506ff5105575c0d31a7015f385397f0d Mon Sep 17 00:00:00 2001 From: Daniel Cazzulino Date: Sun, 19 Mar 2023 20:03:04 -0300 Subject: [PATCH] Resolve wildcard dependency just like central package versions When dependency has a wildcard, we can use the exact same approach we use to resolve empty version in centrally managed package versions. Fixes #64 --- .../NuGetizer.Inference.targets | 21 ++++++++------- src/NuGetizer.Tests/given_packinference.cs | 27 +++++++++++++++++++ 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/NuGetizer.Tasks/NuGetizer.Inference.targets b/src/NuGetizer.Tasks/NuGetizer.Inference.targets index 07cd3e73..fb514756 100644 --- a/src/NuGetizer.Tasks/NuGetizer.Inference.targets +++ b/src/NuGetizer.Tasks/NuGetizer.Inference.targets @@ -432,7 +432,7 @@ Copyright (c) .NET Foundation. All rights reserved. @@ -442,19 +442,20 @@ Copyright (c) .NET Foundation. All rights reserved. <_CandidatePackageIsImplicit>%(PackageReference.IsImplicitlyDefined) - - <_CentrallyManagedDependency Include="@(PackageDependencies)" - Condition="$([MSBuild]::ValueOrDefault('%(Identity)', '').StartsWith('$(_CandidatePackageId)/')) and - $([MSBuild]::ValueOrDefault('%(ParentPackage)', '')) == ''" /> + + <_ResolvedPackageDependency Include="@(PackageDependencies)" + Condition="$([MSBuild]::ValueOrDefault('%(Identity)', '').StartsWith('$(_CandidatePackageId)/')) and + $([MSBuild]::ValueOrDefault('%(ParentPackage)', '')) == ''" /> - - <_CentrallyManagedDependency>%(_CentrallyManagedDependency.Identity) - <_CentrallyManagedVersion>$(_CentrallyManagedDependency.Replace('$(_CandidatePackageId)/', '')) + + <_ResolvedPackageDependency>%(_ResolvedPackageDependency.Identity) + <_ResolvedPackageVersion>$(_ResolvedPackageDependency.Replace('$(_CandidatePackageId)/', '')) - - + + diff --git a/src/NuGetizer.Tests/given_packinference.cs b/src/NuGetizer.Tests/given_packinference.cs index bb58b4f0..198b13b4 100644 --- a/src/NuGetizer.Tests/given_packinference.cs +++ b/src/NuGetizer.Tests/given_packinference.cs @@ -628,5 +628,32 @@ public void when_packing_dependencies_then_includes_satellite_resources_for_priv })); } + [Fact] + public void when_packing_dependencies_then_resolves_wildcard() + { + var result = Builder.BuildProject( + """ + + + Exe + netstandard2.0 + true + Latest + + + + + + + """, output: output); + + result.AssertSuccess(output); + + Assert.DoesNotContain(result.Items, item => item.Matches(new + { + PackFolder = "Dependency", + Version = "4.0.*", + })); + } } }